-- ----------------------------------------------------------------------------
-- MySQL Workbench Migration
-- Migrated Schemata: Mutil_TexasPoker
-- Source Schemata: Mutil_TexasPoker
-- Created: Wed Apr 24 18:25:32 2013
-- ----------------------------------------------------------------------------

SET FOREIGN_KEY_CHECKS = 0;;

-- ----------------------------------------------------------------------------
-- Schema Mutil_TexasPoker
-- ----------------------------------------------------------------------------
DROP SCHEMA IF EXISTS `Mutil_TexasPoker` ;
CREATE SCHEMA IF NOT EXISTS `Mutil_TexasPoker` COLLATE utf8_general_ci ;

------------
---test
---------------

--主键分区 可以
 create table tb(
 `idx` INT NOT NULL AUTO_INCREMENT ,
 `account` varchar(20) NOT null,
 `ct` timestamp  NOT NULL DEFAULT CURRENT_TIMESTAMP ,
 PRIMARY KEY (`idx`)
 --,UNIQUE (`account`)
 )
 COLLATE = utf8_general_ci
   PARTITION BY RANGE (idx)
   (PARTITION p1 VALUES LESS THAN (10000) ENGINE = InnoDB,   
   PARTITION pmax VALUES LESS THAN MAXVALUE ENGINE = InnoDB);
   
   
   --主键约束 不分区可以
      
 create table tb(
 `idx` INT NOT NULL AUTO_INCREMENT ,
 `account` varchar(20) NOT null,
 `ct` timestamp  NOT NULL DEFAULT CURRENT_TIMESTAMP ,
 PRIMARY KEY (`idx`),
 UNIQUE (`account`)
 )
 COLLATE = utf8_general_ci;
   
   ---主键分区 ，约束限制,
    create table tb(
 `idx` INT NOT NULL AUTO_INCREMENT ,
 `account` varchar(20) NOT null,
 `ct` timestamp  NOT NULL DEFAULT CURRENT_TIMESTAMP ,
 PRIMARY KEY (`idx`),
 UNIQUE (`account`)
 )
 COLLATE = utf8_general_ci
   PARTITION BY RANGE (idx)
   (PARTITION p1 VALUES LESS THAN (10000) ENGINE = InnoDB,   
   PARTITION pmax VALUES LESS THAN MAXVALUE ENGINE = InnoDB);
   
   --主键约束分区A PRIMARY KEY must include all columns in the table's partitioning function
   create table tb(
 `idx` INT NOT NULL AUTO_INCREMENT ,
 `account` varchar(20) NOT null,
 `ct` timestamp  NOT NULL DEFAULT CURRENT_TIMESTAMP ,
 PRIMARY KEY (`idx`),
 UNIQUE (`account`)
 )
 COLLATE = utf8_general_ci
   PARTITION BY RANGE (idx)
   SUBPARTITION BY key (account)
   (
   PARTITION p1 VALUES LESS THAN (10000) ENGINE = InnoDB
   (SUBPARTITION s0,
	 SUBPARTITION s1),   
    PARTITION pmax VALUES LESS THAN MAXVALUE ENGINE = InnoDB
	(SUBPARTITION s2,
	 SUBPARTITION s3)    
   );

   ----【约束分区】A PRIMARY KEY must include all columns in the table's partitioning function
  create table tb(
 `idx` INT NOT NULL AUTO_INCREMENT ,
 `account` varchar(20) NOT null,
 `ct` timestamp  NOT NULL DEFAULT CURRENT_TIMESTAMP ,
 PRIMARY KEY (`idx`),
 UNIQUE (`account`)
 )
 COLLATE = utf8_general_ci
 PARTITION BY key (account) partitions 5 ;
 
 
 ---测试10万写入时间
 ---key分区
   create table tb1(
 `idx` INT NOT NULL AUTO_INCREMENT ,
 `num` int NOT null DEFAULT 0 ,
 `account` varchar(20) NOT null,
 `ct` timestamp  NOT NULL DEFAULT CURRENT_TIMESTAMP ,
 PRIMARY KEY (`idx`)
 )
 COLLATE = utf8_general_ci
 PARTITION BY key (idx) partitions 10 ;
 
 --range分区
   create table tb2(
 `idx` INT NOT NULL AUTO_INCREMENT ,
 `num` int NOT null DEFAULT 0 ,
 `account` varchar(20) NOT null,
 `ct` timestamp  NOT NULL DEFAULT CURRENT_TIMESTAMP ,
 PRIMARY KEY (`idx`)
 )
 COLLATE = utf8_general_ci
  PARTITION BY RANGE (idx)
   (PARTITION p1 VALUES LESS THAN (10000) ENGINE = InnoDB,   
    PARTITION p2 VALUES LESS THAN (20000) ENGINE = InnoDB,  
 PARTITION p3 VALUES LESS THAN (30000) ENGINE = InnoDB,  
 PARTITION p4 VALUES LESS THAN (40000) ENGINE = InnoDB,  
 PARTITION p5 VALUES LESS THAN (50000) ENGINE = InnoDB,  
 PARTITION p6 VALUES LESS THAN (60000) ENGINE = InnoDB,  
  PARTITION p7 VALUES LESS THAN (70000) ENGINE = InnoDB, 
  PARTITION p8 VALUES LESS THAN (80000) ENGINE = InnoDB, 
  PARTITION p9 VALUES LESS THAN (90000) ENGINE = InnoDB, 
    PARTITION p10 VALUES LESS THAN (100000) ENGINE = InnoDB, 
   PARTITION pmax VALUES LESS THAN MAXVALUE ENGINE = InnoDB);
 
   
   drop table tb;
      drop PROCEDURE p_test;
 insert into tb(account)values('a'),('b');  
 select * from tb; 	
 desc tb;
 /*A UNIQUE INDEX must include all columns in the table's partitioning function .对于主键+约束 分区*/
 ALTER TABLE tb ADD UNIQUE  (account);
 ALTER TABLE tb ADD INDEX  (account);
 select table_name,partition_name ,table_rows from information_schema.partitions where table_name='tb';
 
 alter table pprimary4 truncate partition p1;
 ALTER TABLE reorganize 可以重新组织分区
 TRUNCATE table tb1;
 set autocommit=0;
  select @@autocommit;
   ----------//
  ----存储过程---
  SHOW  CREATE  PROCEDURE  p_test
  call p_test(10);
----
CREATE PROCEDURE `p_test`(IN `addCount` int,IN tbtype int) 
  BEGIN
  declare i int default 0;
  if(tbtype==1)
  begin
     select 'tb1';
     while i < addCount
      do
     set i = i +1;
     insert into tb1(num,account)values(i,'tb1'); 
     end while;
  end
  else
   begin
      select 'tb2';
      while i < addCount
      do
     set i = i +1;
     insert into tb2(num,account)values(i,'tb2'); 
     end while;
   
   end
 
END
---
CREATE PROCEDURE `p_test`(IN `addCount` int) 
  BEGIN
  declare i int default 0;
  while i < addCount
  do
  set i = i +1;
  insert into tb1(account)values('a'); 
  end while;
END
 ----------
  ----存储过程---//
CREATE PROCEDURE `p_test`(IN `addCount` int,IN tbtype int) 
  BEGIN
  declare i int default 0;
  IF tbtype=1 then
   begin
     select 'tb1';
     while i < addCount
      do
      set i = i+1;
     insert into tb1(num,account)values(i,'tb1'); 
     end while;
   end
  else 
   begin
      select 'tb2';
      while i < addCount
      do
     set i = i +1;
     insert into tb2(num,account)values(i,'tb2'); 
     end while;
   
   end
   
  END IF
 
END




--//单条插入测试
CREATE PROCEDURE `p_atest`(IN `addCount` int,IN tbtype int) 
  BEGIN
  declare i int default 0;
  IF tbtype=1 then   
     select 'tb1';    
     
	  while i < addCount
      do
      set i = i+1;
     insert into tb1(num,account)values(i,'tb1'); 
     end while;
	 
  else    
      select 'tb2';      
   
      while i < addCount
      do
     set i = i +1;
     insert into tb2(num,account)values(i,'tb2'); 
     end while;
	 
  END IF;
 
END
  
  ---//一条语句多条插入
  CREATE PROCEDURE `p_test`(IN `addCount` int,IN tbtype int) 
  BEGIN
   declare temp VARCHAR(1000000);    
  declare i int default 1;
  IF tbtype=1 then   
     select 'tb1';    
     	set @temp=' insert into tb1(num,account)values (1,''tb1'')'; 
	  while i < addCount
      do
      set i = i+1;
	   set @temp=concat(@temp,',( ',i,',''tb1'')'); 
     end while;
	 
  else    
      select 'tb2';      
   set @temp=' insert into tb2(num,account)values (1,''tb2'')'; 
      while i < addCount
      do
     set i = i +1;
     set @temp=concat(@temp,',( ',i,',''tb2'')'); 
     end while;
	 
  END IF;
  PREPARE temp from @temp;  EXECUTE temp;  
END
  
  
  ---------------
  ---测试结果
  ----java---
  -------------
  ----mysql
  ---
   call p_atest(100000,1);/*时间: 9.079ms,14.652ms,16.143ms,| 9.362ms,14.874ms,15.026ms*/
 call p_atest(100000,2);/*13.753ms,15.933ms, 14.598ms,|15.359ms*/
 insert into tb1(num,account)values (1,'tb1'),( 2,'tb1'),( 3,'tb1'),( 4,'tb1'),( 5,'tb1'),( 6,'tb1'),( 7,'tb1'),( 8,'tb1'),( 9,'tb1'),( 10,'tb1')
SET autocommit=0; 
 call p_atest(100000,1);/*时间: 6.688ms,6.826ms,7.313ms|7.638ms*/
commit;
SET autocommit=1; 

SET autocommit=0; 
 call p_atest(100000,2);/*时间: 6.518ms,6.855ms,6.500ms,|7.090ms*/
 ------
  suc
testInsertTb1
2013-04-25 17:54:46:071[INFO]: com.wandian.texas.demo.DbConnectionTest.testInsertTb1(DbConnectionTest.java:173)
testInsertTb1 10000条执行耗时ms:17396,id:0
testBatchInsertTb1
2013-04-25 17:55:26:963[INFO]: com.wandian.texas.demo.DbConnectionTest.testBatchInsertTb1(DbConnectionTest.java:221)
testBatchInsertTb1 10000条执行耗时ms:8473,id:0
testBatchInsertTb1
2013-04-25 17:55:46:605[INFO]: com.wandian.texas.demo.DbConnectionTest.testBatchInsertTb1(DbConnectionTest.java:221)
testBatchInsertTb1 10000条执行耗时ms:8330,id:0
testBatchInsertTb2
2013-04-25 17:56:01:272[INFO]: com.wandian.texas.demo.DbConnectionTest.testBatchInsertTb2(DbConnectionTest.java:244)
testBatchInsertTb2 10000条执行耗时ms:8310,id:0
testBatchInsertTb2
2013-04-25 17:56:19:618[INFO]: com.wandian.texas.demo.DbConnectionTest.testBatchInsertTb2(DbConnectionTest.java:244)
testBatchInsertTb2 10000条执行耗时ms:8200,id:0
--平均数据库插入 (1万/8.3)*1=0.120万

1367487087307
thread-BoneCPConn1 exit
1367487096558
BoneCPConn addCount:10000 并发线程数:1======>运行完毕!耗时为：9251ms

1367487237061
thread-dbMgr1 exit
1367487246930
dbMgr addCount:10000 并发线程数:1======>运行完毕!耗时为：9869ms

dbMgr testBatchInsertTb2 addCount:10000 并发线程数:1======>运行完毕!耗时为：10288ms

1367487298692
thread-DBCP1 exit
1367487310058
DBCP addCount:10000 并发线程数:1======>运行完毕!耗时为：11366ms


1367488235734
BoneCPConn-0open:0
thread-BoneCPConn1 exit
1367488245866
BoneCPConn addCount:10000 并发线程数:1======>运行完毕!耗时为：10132ms
BoneCPConn testBatchInsertTb2 addCount:10000 并发线程数:1======>运行完毕!耗时为：9989ms


1367487335411
thread-C3P01 exit
1367487346036
C3P0 addCount:10000 并发线程数:1======>运行完毕!耗时为：10625ms
---
1367488128185
dbMgr-0open:0
dbMgr-1open:1
thread-dbMgr1 exit
thread-dbMgr2 exit
1367488138325
dbMgr addCount:10000 并发线程数:2======>运行完毕!耗时为：10140ms
1367488180373
BoneCPConn-0open:0
BoneCPConn-1open:1
thread-BoneCPConn1 exit
thread-BoneCPConn2 exit
1367488191033
BoneCPConn addCount:10000 并发线程数:2======>运行完毕!耗时为：10660ms
----

testBatchInsertTb1
2013-04-25 18:31:18:614[INFO]: com.wandian.texas.demo.DbConnectionTest.testBatchInsertTb1(DbConnectionTest.java:305)
线程：3testBatchInsertTb1 10000条执行耗时ms:12282,id:0
线程执行命令完成,id:3 cmdid:3
2013-04-25 18:31:18:662[INFO]: com.wandian.texas.demo.DbConnectionTest.testBatchInsertTb1(DbConnectionTest.java:305)
线程：4testBatchInsertTb1 10000条执行耗时ms:12330,id:0
线程执行命令完成,id:4 cmdid:3
2013-04-25 18:31:19:078[INFO]: com.wandian.texas.demo.DbConnectionTest.testBatchInsertTb1(DbConnectionTest.java:305)
线程：0testBatchInsertTb1 10000条执行耗时ms:12745,id:0
线程执行命令完成,id:0 cmdid:3
2013-04-25 18:31:19:129[INFO]: com.wandian.texas.demo.DbConnectionTest.testBatchInsertTb1(DbConnectionTest.java:305)
线程：1testBatchInsertTb1 10000条执行耗时ms:12797,id:0
线程执行命令完成,id:1 cmdid:3
2013-04-25 18:31:19:163[INFO]: com.wandian.texas.demo.DbConnectionTest.testBatchInsertTb1(DbConnectionTest.java:305)
线程：2testBatchInsertTb1 10000条执行耗时ms:12831,id:0
线程执行命令完成,id:2 cmdid:3
testBatchInsertTb2
2013-04-25 18:32:00:125[INFO]: com.wandian.texas.demo.DbConnectionTest.testBatchInsertTb2(DbConnectionTest.java:329)
线程：4testBatchInsertTb2 10000条执行耗时ms:12313,id:0
线程执行命令完成,id:4 cmdid:4
2013-04-25 18:32:00:125[INFO]: com.wandian.texas.demo.DbConnectionTest.testBatchInsertTb2(DbConnectionTest.java:329)
线程：3testBatchInsertTb2 10000条执行耗时ms:12313,id:0
线程执行命令完成,id:3 cmdid:4
2013-04-25 18:32:00:587[INFO]: com.wandian.texas.demo.DbConnectionTest.testBatchInsertTb2(DbConnectionTest.java:329)
线程：0testBatchInsertTb2 10000条执行耗时ms:12775,id:0
线程执行命令完成,id:0 cmdid:4
2013-04-25 18:32:00:684[INFO]: com.wandian.texas.demo.DbConnectionTest.testBatchInsertTb2(DbConnectionTest.java:329)
线程：1testBatchInsertTb2 10000条执行耗时ms:12872,id:0
线程执行命令完成,id:1 cmdid:4
2013-04-25 18:32:00:688[INFO]: com.wandian.texas.demo.DbConnectionTest.testBatchInsertTb2(DbConnectionTest.java:329)
线程：2testBatchInsertTb2 10000条执行耗时ms:12876,id:0
线程执行命令完成,id:2 cmdid:4
--平均数据库插入 (1万/12.7)*5=0.393万

-----
1367488365351
BoneCPConn-0open:0
BoneCPConn-2open:2
BoneCPConn-1open:1
BoneCPConn-3open:3
BoneCPConn-4open:4
thread-BoneCPConn1 exit
thread-BoneCPConn2 exit
thread-BoneCPConn3 exit
thread-BoneCPConn4 exit
thread-BoneCPConn5 exit
1367488379956
PreparedStatement
BoneCPConn addCount:10000 并发线程数:5======>运行完毕!耗时为：14605ms
dbMgr addCount:10000 并发线程数:5======>运行完毕!耗时为：14393ms
DBCP addCount:10000 并发线程数:5======>运行完毕!耗时为：15708ms

Statement
BoneCPConn testBatchInsertTb2 addCount:10000 并发线程数:5======>运行完毕!耗时为：14385ms
dbMgr testBatchInsertTb2 addCount:10000 并发线程数:5======>运行完毕!耗时为：15369ms

  -----
BoneCPConn testBatchInsertTb2 addCount:10000 并发线程数:5======>运行完毕!耗时为：28659ms


dbMgr testBatchInsertTb2 addCount:10000 并发线程数:5======>运行完毕!耗时为：13263ms
BoneCPConn testBatchInsertTb2 addCount:10000 并发线程数:5======>运行完毕!耗时为：13259ms


  ----
  --MariaDB----
  ---
  testInsertTb1
2013-04-26 15:44:03:263[INFO]: com.wandian.texas.demo.DbConnectionTest.testInsertTb1(DbConnectionTest.java:240)
线程：0testInsertTb1 10000条执行耗时ms:8328,id:0
线程执行命令完成,id:0 cmdid:1
testInsertTb2
2013-04-26 15:45:07:857[INFO]: com.wandian.texas.demo.DbConnectionTest.testInsertTb2(DbConnectionTest.java:265)
线程：0testInsertTb2 10000条执行耗时ms:8066,id:0
线程执行命令完成,id:0 cmdid:2
testBatchInsertTb1
2013-04-26 15:45:34:649[INFO]: com.wandian.texas.demo.DbConnectionTest.testBatchInsertTb1(DbConnectionTest.java:305)
线程：0testBatchInsertTb1 10000条执行耗时ms:8186,id:0
线程执行命令完成,id:0 cmdid:3
testBatchInsertTb2
2013-04-26 15:46:32:290[INFO]: com.wandian.texas.demo.DbConnectionTest.testBatchInsertTb2(DbConnectionTest.java:329)
线程：0testBatchInsertTb2 10000条执行耗时ms:7987,id:0
线程执行命令完成,id:0 cmdid:4
 ----
 ---5多线程
 suc
testInsertTb1
2013-04-26 15:51:01:078[INFO]: com.wandian.texas.demo.DbConnectionTest.testInsertTb1(DbConnectionTest.java:241)
线程：2testInsertTb1 10000条执行耗时ms:12254,id:0
线程执行命令完成,id:2 cmdid:1
2013-04-26 15:51:01:094[INFO]: com.wandian.texas.demo.DbConnectionTest.testInsertTb1(DbConnectionTest.java:241)
线程：3testInsertTb1 10000条执行耗时ms:12270,id:0
线程执行命令完成,id:3 cmdid:1
2013-04-26 15:51:01:236[INFO]: com.wandian.texas.demo.DbConnectionTest.testInsertTb1(DbConnectionTest.java:241)
线程：4testInsertTb1 10000条执行耗时ms:12412,id:0
线程执行命令完成,id:4 cmdid:1
2013-04-26 15:51:01:353[INFO]: com.wandian.texas.demo.DbConnectionTest.testInsertTb1(DbConnectionTest.java:241)
线程：1testInsertTb1 10000条执行耗时ms:12529,id:0
线程执行命令完成,id:1 cmdid:1
2013-04-26 15:51:01:595[INFO]: com.wandian.texas.demo.DbConnectionTest.testInsertTb1(DbConnectionTest.java:241)
线程：0testInsertTb1 10000条执行耗时ms:12771,id:0
线程执行命令完成,id:0 cmdid:1
testBatchInsertTb1
2013-04-26 15:51:36:761[INFO]: com.wandian.texas.demo.DbConnectionTest.testBatchInsertTb1(DbConnectionTest.java:306)
线程：2testBatchInsertTb1 10000条执行耗时ms:12634,id:0
线程执行命令完成,id:2 cmdid:3
2013-04-26 15:51:36:854[INFO]: com.wandian.texas.demo.DbConnectionTest.testBatchInsertTb1(DbConnectionTest.java:306)
线程：3testBatchInsertTb1 10000条执行耗时ms:12727,id:0
线程执行命令完成,id:3 cmdid:3
2013-04-26 15:51:36:911[INFO]: com.wandian.texas.demo.DbConnectionTest.testBatchInsertTb1(DbConnectionTest.java:306)
线程：4testBatchInsertTb1 10000条执行耗时ms:12784,id:0
线程执行命令完成,id:4 cmdid:3
2013-04-26 15:51:37:120[INFO]: com.wandian.texas.demo.DbConnectionTest.testBatchInsertTb1(DbConnectionTest.java:306)
线程：1testBatchInsertTb1 10000条执行耗时ms:12993,id:0
线程执行命令完成,id:1 cmdid:3
2013-04-26 15:51:37:937[INFO]: com.wandian.texas.demo.DbConnectionTest.testBatchInsertTb1(DbConnectionTest.java:306)
线程：0testBatchInsertTb1 10000条执行耗时ms:13810,id:0
线程执行命令完成,id:0 cmdid:3
testBatchInsertTb2
2013-04-26 15:52:37:501[INFO]: com.wandian.texas.demo.DbConnectionTest.testBatchInsertTb2(DbConnectionTest.java:330)
线程：2testBatchInsertTb2 10000条执行耗时ms:12414,id:0
线程执行命令完成,id:2 cmdid:4
2013-04-26 15:52:37:609[INFO]: com.wandian.texas.demo.DbConnectionTest.testBatchInsertTb2(DbConnectionTest.java:330)
线程：3testBatchInsertTb2 10000条执行耗时ms:12522,id:0
线程执行命令完成,id:3 cmdid:4
2013-04-26 15:52:37:659[INFO]: com.wandian.texas.demo.DbConnectionTest.testBatchInsertTb2(DbConnectionTest.java:330)
线程：4testBatchInsertTb2 10000条执行耗时ms:12572,id:0
线程执行命令完成,id:4 cmdid:4
2013-04-26 15:52:38:118[INFO]: com.wandian.texas.demo.DbConnectionTest.testBatchInsertTb2(DbConnectionTest.java:330)
线程：1testBatchInsertTb2 10000条执行耗时ms:13031,id:0
线程执行命令完成,id:1 cmdid:4
2013-04-26 15:52:38:918[INFO]: com.wandian.texas.demo.DbConnectionTest.testBatchInsertTb2(DbConnectionTest.java:330)
线程：0testBatchInsertTb2 10000条执行耗时ms:13831,id:0
线程执行命令完成,id:0 cmdid:4
testBatchInsertTb2
2013-04-26 15:53:02:978[INFO]: com.wandian.texas.demo.DbConnectionTest.testBatchInsertTb2(DbConnectionTest.java:330)
线程：2testBatchInsertTb2 10000条执行耗时ms:12535,id:0
线程执行命令完成,id:2 cmdid:4
2013-04-26 15:53:03:170[INFO]: com.wandian.texas.demo.DbConnectionTest.testBatchInsertTb2(DbConnectionTest.java:330)
线程：3testBatchInsertTb2 10000条执行耗时ms:12727,id:0
线程执行命令完成,id:3 cmdid:4
2013-04-26 15:53:03:304[INFO]: com.wandian.texas.demo.DbConnectionTest.testBatchInsertTb2(DbConnectionTest.java:330)
线程：4testBatchInsertTb2 10000条执行耗时ms:12861,id:0
线程执行命令完成,id:4 cmdid:4
2013-04-26 15:53:03:578[INFO]: com.wandian.texas.demo.DbConnectionTest.testBatchInsertTb2(DbConnectionTest.java:330)
线程：1testBatchInsertTb2 10000条执行耗时ms:13135,id:0
线程执行命令完成,id:1 cmdid:4
2013-04-26 15:53:04:487[INFO]: com.wandian.texas.demo.DbConnectionTest.testBatchInsertTb2(DbConnectionTest.java:330)
线程：0testBatchInsertTb2 10000条执行耗时ms:14043,id:0
线程执行命令完成,id:0 cmdid:4

 -----------
-- ----------------------------------------------------------------------------
-- Table Mutil_TexasPoker.Game_EndLog
-- ----------------------------------------------------------------------------
CREATE  TABLE IF NOT EXISTS `Mutil_TexasPoker`.`Game_EndLog` (
  `GameId` INT NOT NULL ,
  `BonusPools` VARCHAR(50) NULL ,
  `SystemWinPools` VARCHAR(50) NULL ,
  `SystemWin` DOUBLE NULL ,
  `Winners` VARCHAR(50) NULL ,
  `idx_win` VARCHAR(200) NULL ,
  `WinMoneys` VARCHAR(50) NULL ,
  `MaxHands` VARCHAR(100) NULL ,
  `EndTime` DATETIME NULL ,
  PRIMARY KEY (`GameId`) )
COLLATE = utf8_general_ci;

-- ----------------------------------------------------------------------------
-- Table Mutil_TexasPoker.Game_TableLog
-- ----------------------------------------------------------------------------
CREATE  TABLE IF NOT EXISTS `Mutil_TexasPoker`.`Game_TableLog` (
  `Id` INT NOT NULL AUTO_INCREMENT ,
  `ServerId` INT NULL ,
  `RoomdId` INT NULL ,
  `SeatId` INT NULL ,
  `GameId` INT NULL ,
  `UserId` INT NULL ,
  `idx` INT NULL ,
  `Money` DOUBLE NULL ,
  `Stake` DOUBLE NULL COMMENT '买入筹码,进入游戏的时候分离,站起,退出的时候合并' ,
  `LeftMoney` DOUBLE NULL COMMENT '剩余金额' ,
  `Bet` DOUBLE NULL ,
  `Win` DOUBLE NULL ,
  `CreateTime` DATETIME NULL COMMENT '兑换时间' ,
  `Memo` VARCHAR(50) NULL ,
  PRIMARY KEY (`Id`) )
COLLATE = utf8_general_ci;

-- ----------------------------------------------------------------------------
-- Table Mutil_TexasPoker.PlayerInfo
-- ----------------------------------------------------------------------------
CREATE  TABLE IF NOT EXISTS `Mutil_TexasPoker`.`PlayerInfo` (
  `UserId` INT NOT NULL AUTO_INCREMENT ,
  `idx` INT NOT NULL ,
  `ServerId` INT NOT NULL ,
  `UserName` VARCHAR(100) NOT NULL ,
  `NickName` VARCHAR(200) NOT NULL ,
  `HeadImage` TINYBLOB NULL ,
  `Password` CHAR(40) NULL DEFAULT NULL ,
  `PasswordSalt` CHAR(10) NULL DEFAULT NULL ,
  `Sex` TINYINT(1) NOT NULL DEFAULT 0 ,
  `RealName` CHAR(30) NULL DEFAULT NULL ,
  `Email` VARCHAR(100) NULL DEFAULT NULL ,
  `Mobile` CHAR(11) NULL DEFAULT NULL ,
  `Status` TINYINT UNSIGNED NOT NULL DEFAULT 0 COMMENT '当前状态,0正常,-1禁用' ,
  `CreateDate` timestamp  NOT NULL DEFAULT CURRENT_TIMESTAMP  COMMENT '插件日期' ,
  `Score` INT NULL ,
  `RankScore` INT NULL COMMENT '积分排行' ,
  `Money` float(10,2) not null  default 0 ,
  `RankMoney` INT NULL COMMENT '财富排行' ,
  `Stake` float(10,2) not null  default 0 COMMENT '当前随身携带' ,
  `GameBet` float(10,2) not null  default 0 NULL ,
  `CurrentServerId` INT NULL ,
  `CurrentRoomId` INT NULL ,
  `IsPlaying` TINYINT UNSIGNED NULL COMMENT '是否正在玩游戏，当置为0否的时候,将Stake加入money，重新统计Rank' ,
  `Gold` INT NULL ,
  `RankGold` INT NULL ,
  `MaxHandCard` VARCHAR(50) NULL COMMENT '最大手牌' ,
  `MaxWin` INT NULL COMMENT '最高赢点' ,
  `MaxMoney` float(10,2) not null  default 0 NULL COMMENT '最大资产' ,
  `PlayCount` INT NULL COMMENT '已玩局数' ,
  `WinCount` INT NULL COMMENT '赢次数' ,
  `Icon` VARCHAR(50) NULL COMMENT '头像url' ,
  `CurrentState` TINYINT UNSIGNED NULL COMMENT '当前状态,1登录,0未登录' ,
  `LastLoginTime` timestamp  NULL COMMENT '最后登录时间' ,
  `LastLogOutTime` timestamp  NULL ,
  `LastLoginIp` VARCHAR(50) NULL COMMENT '最后登录ip' ,
  PRIMARY KEY (`UserId`) )
COLLATE = utf8_general_ci
PARTITION BY RANGE (UserId)
(PARTITION p1 VALUES LESS THAN (10000) ENGINE = InnoDB,  
 PARTITION p2 VALUES LESS THAN (20000) ENGINE = InnoDB,  
 PARTITION p3 VALUES LESS THAN (30000) ENGINE = InnoDB,  
 PARTITION p4 VALUES LESS THAN (40000) ENGINE = InnoDB,  
 PARTITION p5 VALUES LESS THAN (50000) ENGINE = InnoDB,  
 PARTITION p6 VALUES LESS THAN (60000) ENGINE = InnoDB,  
  PARTITION p7 VALUES LESS THAN (70000) ENGINE = InnoDB, 
  PARTITION p8 VALUES LESS THAN (80000) ENGINE = InnoDB, 
  PARTITION p9 VALUES LESS THAN (90000) ENGINE = InnoDB, 
    PARTITION p10 VALUES LESS THAN (100000) ENGINE = InnoDB, 
   PARTITION pmax VALUES LESS THAN MAXVALUE ENGINE = InnoDB) 
;

-- ----------------------------------------------------------------------------
-- Table Mutil_TexasPoker.t_Config
-- ----------------------------------------------------------------------------
CREATE  TABLE IF NOT EXISTS `Mutil_TexasPoker`.`t_Config` (
  `CKey` VARCHAR(50) NOT NULL COMMENT '键' ,
  `CValue` VARCHAR(50) NULL COMMENT '键值' ,
  `FValue` DOUBLE NULL ,
  `Memo` VARCHAR(100) NULL COMMENT '备注' ,
  PRIMARY KEY (`CKey`) )
COLLATE = utf8_general_ci;

-- ----------------------------------------------------------------------------
-- Table Mutil_TexasPoker.Bonus_CenterServerLog
-- ----------------------------------------------------------------------------
CREATE  TABLE IF NOT EXISTS `Mutil_TexasPoker`.`Bonus_CenterServerLog` (
  `Id` INT NOT NULL ,
  `CornucopiaType` TINYINT UNSIGNED NULL COMMENT '是游戏端产生的0，还是中心服务器主动产生的,1' ,
  `IsAllow` TINYINT(1) NULL COMMENT '有没有允许' ,
  `IsUsing` TINYINT(1) NULL COMMENT '有没有被使用' ,
  `IsSend` TINYINT(1) NULL COMMENT '游戏结束有没有发出去' ,
  `CornucopiaId` INT NULL ,
  `CornucopiaCallBack` VARCHAR(50) NOT NULL ,
  `ServerId` INT NULL ,
  `RoomId` INT NULL ,
  `GameId` INT NULL ,
  `SeatId` INT NULL ,
  `UserId` INT NULL ,
  `idx` INT NULL ,
  `NickName` VARCHAR(50) NULL ,
  `CardType` INT NULL ,
  `WinMoney` DOUBLE NULL ,
  `MaxCards` VARCHAR(50) NULL ,
  `WinTime` DATETIME NULL ,
  PRIMARY KEY (`CornucopiaCallBack`) )
COLLATE = utf8_general_ci;

-- ----------------------------------------------------------------------------
-- Table Mutil_TexasPoker.Bonus_GameServerLog
-- ----------------------------------------------------------------------------
CREATE  TABLE IF NOT EXISTS `Mutil_TexasPoker`.`Bonus_GameServerLog` (
  `Id` INT NOT NULL ,
  `CornucopiaCallBack` VARCHAR(50) NOT NULL ,
  `CornucopiaType` TINYINT UNSIGNED NULL ,
  `IsUsing` TINYINT(1) NULL ,
  `IsSend` TINYINT(1) NULL ,
  `ServerId` INT NULL ,
  `RoomId` INT NULL ,
  `GameId` INT NULL ,
  `SeatId` INT NULL ,
  `UserId` INT NULL ,
  `idx` INT NULL ,
  `NickName` VARCHAR(50) NULL ,
  `WinMoney` DOUBLE NULL ,
  `CardType` INT NULL ,
  `MaxCards` VARCHAR(50) NULL ,
  `WinTime` DATETIME NULL ,
  `Memo` VARCHAR(50) NULL ,
  PRIMARY KEY (`CornucopiaCallBack`) )
COLLATE = utf8_general_ci;

-- ----------------------------------------------------------------------------
-- Table Mutil_TexasPoker.Game_BeginLog
-- ----------------------------------------------------------------------------
CREATE  TABLE IF NOT EXISTS `Mutil_TexasPoker`.`Game_BeginLog` (
  `Id` INT NOT NULL AUTO_INCREMENT COMMENT '游戏局id' ,
  `ServerId` INT NULL COMMENT '服务器id' ,
  `RoomId` INT NULL COMMENT '房间id' ,
  `RoomCode` INT NULL ,
  `RoomName` VARCHAR(50) NULL COMMENT '房间名字' ,
  `State` TINYINT UNSIGNED NULL DEFAULT 0 ,
  `PlayerNum` INT NULL COMMENT '玩家数' ,
  `SeatCount` INT NULL COMMENT '椅子的数量' ,
  `prevId` INT NULL COMMENT '上一局游戏id' ,
  `PublicCard` VARCHAR(50) NULL COMMENT '公共牌' ,
  `SeatUserIds` VARCHAR(100) NULL ,
  `SeatIdx` VARCHAR(200) NULL ,
  `DealerId` INT NULL COMMENT '庄家id' ,
  `MinBindUserId` INT NULL COMMENT '小盲注id' ,
  `MinBind` INT NULL COMMENT '小盲注金额' ,
  `MaxBindUserId` INT NULL ,
  `MaxBind` INT NULL ,
  `DlayTime` INT NULL COMMENT '倒计时数' ,
  `MinStake` INT NULL COMMENT '最小携带金额,就是最小买入筹码' ,
  `MaxStake` INT NULL COMMENT '最大携带金额,就是最大买入筹码' ,
  `NewChip` INT NULL COMMENT '新来的玩家系统自动下注' ,
  `NewUserIds` VARCHAR(50) NULL DEFAULT '0,0,0,0,0,0,0,0,0' COMMENT '新来玩家的ids[0,0,0,0,0,0,0,0,0]表示9个坐位没有新来人' ,
  `WatchUserIds` VARCHAR(50) NULL COMMENT '观战用户ids' ,
  `StartChips` VARCHAR(50) NULL COMMENT '系统给1-9玩家的初始下注,可以根据大小盲注以及新来的人推导出来' ,
  `SeatUserId1` INT NULL COMMENT '一号坐位玩家id，-1标识椅子未显示，如3人赛' ,
  `SeatUserId2` INT NULL ,
  `SeatUserId3` INT NULL ,
  `SeatUserId4` INT NULL ,
  `SeatUserId5` INT NULL ,
  `SeatUserId6` INT NULL ,
  `SeatUserId7` INT NULL ,
  `SeatUserId8` INT NULL ,
  `SeatUserId9` INT NULL ,
  `HandCard1` VARCHAR(50) NULL COMMENT '玩家1手牌' ,
  `HandCard2` VARCHAR(50) NULL ,
  `HandCard3` VARCHAR(50) NULL ,
  `HandCard4` VARCHAR(50) NULL ,
  `HandCard5` VARCHAR(50) NULL ,
  `HandCard6` VARCHAR(50) NULL ,
  `HandCard7` VARCHAR(50) NULL ,
  `HandCard8` VARCHAR(50) NULL ,
  `HandCard9` VARCHAR(50) NULL ,
  `PokerIndexs` VARCHAR(200) NULL ,
  `StartTime` DATETIME NULL COMMENT '游戏开始时间' ,
  PRIMARY KEY (`Id`) )
COLLATE = utf8_general_ci;

-- ----------------------------------------------------------------------------
-- Table Mutil_TexasPoker.t_Friends
-- ----------------------------------------------------------------------------
CREATE  TABLE IF NOT EXISTS `Mutil_TexasPoker`.`t_Friends` (
  `Id` INT NOT NULL AUTO_INCREMENT COMMENT '好友表' ,
  `UserId` INT NULL COMMENT '主动加的用户id' ,
  `NickName` VARCHAR(50) NULL COMMENT '昵称' ,
  `FriendId` INT NULL COMMENT '接受主动加好友的用户id' ,
  `FriendNickName` VARCHAR(50) NULL COMMENT '好友昵称' ,
  `state` TINYINT UNSIGNED NULL COMMENT '好友状态,0,申请未接受,1成为好友,-1被迫分手' ,
  `CreateTime` DATETIME NULL ,
  PRIMARY KEY (`Id`) )
COLLATE = utf8_general_ci;

-- ----------------------------------------------------------------------------
-- Table Mutil_TexasPoker.t_ServerList
-- ----------------------------------------------------------------------------
CREATE  TABLE IF NOT EXISTS `Mutil_TexasPoker`.`t_ServerList` (
  `ServerId` INT NOT NULL COMMENT '服务器id' ,
  `ServerIndex` INT NULL ,
  `ServerName` VARCHAR(50) NULL COMMENT '服务器名称' ,
  `ServerKey` VARCHAR(50) NULL ,
  `RoomCount` INT NULL DEFAULT 100 COMMENT '房间数' ,
  `ServerState` TINYINT UNSIGNED NULL COMMENT '服务状态' ,
  `ServerIp` VARCHAR(50) NULL COMMENT '服务器ip' ,
  `Port` INT NOT NULL COMMENT '端口' ,
  `SessionMaxCount` INT NOT NULL COMMENT '最大承受用户量' ,
  `SessionWarnCount` INT NULL COMMENT '当剩余资源小于等于此数的时候，系统日志会警告' ,
  `CmdThreadCount` INT NOT NULL COMMENT '线程池数量' ,
  `CmdQueueCount` INT NOT NULL COMMENT '线程命令队列长度' ,
  `CurrentSessionCount` INT NULL ,
  `Description` VARCHAR(50) NULL COMMENT '服务器描述' ,
  `State` TINYINT UNSIGNED NULL COMMENT '状态，0正常，1禁用' ,
  `CreateDate` DATETIME NOT NULL ,
  `SendMoney` DOUBLE NULL DEFAULT 0.0 ,
  `NotSendMoney` DOUBLE NULL DEFAULT 0.0 ,
  `LastLoginTime` DATETIME NULL ,
  `LastLogOutTime` DATETIME NULL )
COLLATE = utf8_general_ci;

-- ----------------------------------------------------------------------------
-- Table Mutil_TexasPoker.AccountMoneyLog
-- ----------------------------------------------------------------------------
CREATE  TABLE IF NOT EXISTS `Mutil_TexasPoker`.`AccountMoneyLog` (
  `Id` INT NOT NULL AUTO_INCREMENT ,
  `UserId` INT NOT NULL ,
  `idx` INT NULL ,
  `Bet` DOUBLE NOT NULL ,
  `Win` DOUBLE NOT NULL ,
  `CreateTime` DATETIME NOT NULL ,
  PRIMARY KEY (`Id`) )
COLLATE = utf8_general_ci;

-- ----------------------------------------------------------------------------
-- Table Mutil_TexasPoker.t_PublicMsg
-- ----------------------------------------------------------------------------
CREATE  TABLE IF NOT EXISTS `Mutil_TexasPoker`.`t_PublicMsg` (
  `Id` INT NOT NULL AUTO_INCREMENT ,
  `Title` VARCHAR(50) NULL ,
  `IsValid` TINYINT UNSIGNED NULL COMMENT '是否有效' ,
  `IsShow` TINYINT UNSIGNED NULL COMMENT '是否显示' ,
  `OrderNum` INT NULL COMMENT '显示顺序' ,
  `Announcement` VARCHAR(300) NULL COMMENT '公告内容html' ,
  `StartTime` DATETIME NULL ,
  `EndTime` DATETIME NULL ,
  PRIMARY KEY (`Id`) )
COLLATE = utf8_general_ci;

-- ----------------------------------------------------------------------------
-- Table Mutil_TexasPoker.Game_StepLog
-- ----------------------------------------------------------------------------
CREATE  TABLE IF NOT EXISTS `Mutil_TexasPoker`.`Game_StepLog` (
  `Id` INT NOT NULL AUTO_INCREMENT ,
  `GameId` INT NULL COMMENT '游戏id' ,
  `ServerId` INT NULL COMMENT '服务器id' ,
  `Step` INT NULL COMMENT '步骤序号' ,
  `UserId` INT NULL ,
  `idx` INT NULL ,
  `SeatId` INT NULL ,
  `RoundNum` TINYINT UNSIGNED NULL COMMENT '属于第几局，1-4，分别代表，开始，翻牌，转牌，河牌' ,
  `ActionType` TINYINT UNSIGNED NULL COMMENT '操作类型,-1放弃，0看牌|-1弃牌|1跟注|2加注|3全押|10小盲注|11大盲注|12新进入,系统已自动下' ,
  `LeftTime` INT NULL COMMENT '剩余时间' ,
  `GiveChip` DOUBLE NULL COMMENT '下注金额' ,
  `SiteChip` DOUBLE NULL COMMENT '桌上金额' ,
  `Stake` DOUBLE NULL COMMENT '随身携带金额' ,
  `TotalChip` DOUBLE NULL COMMENT '总下注' ,
  `CurrentState` TINYINT UNSIGNED NULL COMMENT '当然状态,0正常,-1站起,-2离开房间' ,
  `CreateTime` DATETIME NULL COMMENT '操作时间' ,
  `Memo` VARCHAR(50) NULL ,
  PRIMARY KEY (`Id`) )
COLLATE = utf8_general_ci;

-- ----------------------------------------------------------------------------
-- View Mutil_TexasPoker.sp_AutoAddNum
-- ----------------------------------------------------------------------------
-- USE `Mutil_TexasPoker`;
-- 
-- 
-- 
-- 
-- 
-- 
-- 
-- -- =============================================
-- -- Author:		long
-- -- Create date: 2012-10-14
-- -- Description:	测试数据库number自动增加
-- -- =============================================
-- CREATE  OR REPLACE PROCEDURE [dbo].[sp_AutoAddNum]
-- 	@Id int
-- AS
-- BEGIN
-- SET NOCOUNT ON;
-- begin transaction
-- 	update t_test  set [count]=[count]+1 where id=@Id;
-- 	Select [count] From t_test where id=@Id
-- commit transaction
-- END
-- 
-- 
-- 
-- 
-- 
-- 
-- 
-- ;

-- ----------------------------------------------------------------------------
-- View Mutil_TexasPoker.sp_AutoAddNum1
-- ----------------------------------------------------------------------------
-- USE `Mutil_TexasPoker`;
-- 
-- 
-- -- =============================================
-- -- Author:		long
-- -- Create date: 2012-10-14
-- -- Description:	测试数据库number自动增加
-- -- =============================================
-- CREATE  OR REPLACE PROCEDURE [dbo].[sp_AutoAddNum1]
-- 	@Id int,
--     @Result int output
-- AS
-- BEGIN
-- 	Select @Result=[Count] From t_test where id=@Id
-- END
-- 
-- 
-- ;

-- ----------------------------------------------------------------------------
-- View Mutil_TexasPoker.sp_AddPlayMoneyLogWhenError
-- ----------------------------------------------------------------------------
-- USE `Mutil_TexasPoker`;
-- 
-- 
-- 
-- 
-- 
-- -- =============================================
-- -- Author:		peng cheng long
-- -- Create date: 2012-12-29
-- -- Description:	
-- -- =============================================
-- CREATE  OR REPLACE PROCEDURE [dbo].[sp_AddPlayMoneyLogWhenError]
--     @UserId int,
--     @idx int,
-- 	@Bet float,
--     @Win float
-- AS
-- BEGIN
-- 	SET NOCOUNT OFF;
--     INSERT INTO AccountMoneyLog(UserId,idx,Bet,Win,CreateTime) VALUES(@UserId,@idx,@Bet,@Win,getdate())   
--     UPDATE dbo.PlayerInfo SET GameBet=0 WHERE UserId=@UserId
-- END
-- 
-- 
-- 
-- 
-- ;

-- ----------------------------------------------------------------------------
-- View Mutil_TexasPoker.sp_Pagination
-- ----------------------------------------------------------------------------
-- USE `Mutil_TexasPoker`;
-- 
-- -- =============================================
-- -- Author:		peng cheng long
-- -- Create date: 2012-125
-- -- Description:	分页存储过程
-- -- =============================================
-- CREATE  OR REPLACE PROCEDURE [dbo].[sp_Pagination]	
-- 	@strTableName varchar(2000) = '',
-- 	@strWhere varchar(500) = '',
-- 	@strSelectColumns varchar(1000) = '*',
-- 	@currentPage int=1,
-- 	@pageSize int =12,
-- 	@orderby varchar(400) = '',
-- 	@PKName varchar(50) = 'Id',
-- 	@total int output
-- AS
-- BEGIN
-- 	-- SET NOCOUNT ON added to prevent extra result sets from
-- 	-- interfering with SELECT statements.
-- 	SET NOCOUNT ON;
-- 	declare @startRow int
-- 	declare @endRow int
-- 	declare @strsql nvarchar(4000)
-- 
-- 	set @strsql = 'select @total= count('+@PKName+') from ' + @strTableName + ' ' + @strWhere
-- 
-- 	exec sp_executesql @strsql,N'@total int output',@total output
-- 	
-- 	if @orderby is null or @orderby = ''
-- 		begin
-- 			set @orderby='Order by '+@PKName
-- 		end
-- 	
-- 	if @currentPage >0 and @pageSize >0
-- 	begin
-- 		set @startRow = (@currentPage-1) * @pageSize 
-- 		set @endRow = @currentPage * @pageSize
-- 
-- 		set @strsql = N'select * from (select ROW_NUMBER() OVER ('+@orderby+') AS RowNum ,'+@strSelectColumns+' from '+ @strTableName +' '+ 
-- 		@strWhere +') as mainTable Where mainTable.RowNum>'+Convert(varchar(15),@startRow)+' and mainTable.RowNum<='+Convert(varchar(15),@endRow)
-- 		
-- 	end
-- 	else 
-- 		set @strsql = N'select * from (select ROW_NUMBER() OVER ('+@orderby+') AS RowNum ,'+@strSelectColumns+' from '+ @strTableName +' '+ @strWhere +') as mainTable'
-- 		
-- 		EXECUTE sp_executesql @strsql
-- 
-- 		
-- 		--
-- 	--select @strsql
-- END
-- ;

-- ----------------------------------------------------------------------------
-- View Mutil_TexasPoker.TableView
-- ----------------------------------------------------------------------------
-- USE `Mutil_TexasPoker`;
-- CREATE  OR REPLACE VIEW [dbo].[TableView]
-- AS
-- SELECT     TOP (100) PERCENT O.name AS TableName, ISNULL(CASE WHEN C.column_id = 1 THEN PTB.[value] END, N'') AS TableDesc, 
--                       C.column_id AS Column_id, C.name AS ColumnName, ISNULL(IDX_1.PrimaryKey, N'') AS PrimaryKey, 
--                       CASE WHEN C.is_identity = 1 THEN N'√' ELSE N'' END AS [IDENTITY], CASE WHEN C.is_computed = 1 THEN N'√' ELSE N'' END AS Computed, 
--                       T.name AS Type, C.max_length AS Length, C.precision AS Precision, C.scale AS Scale, 
--                       CASE WHEN C.is_nullable = 1 THEN N'√' ELSE N'' END AS NullAble, ISNULL(D.definition, N'') AS [Default], ISNULL(PFD.value, N'') AS ColumnDesc, 
--                       ISNULL(IDX_1.IndexName, N'') AS IndexName, ISNULL(IDX_1.Sort, N'') AS IndexSort, O.create_date AS Create_Date, 
--                       O.modify_date AS Modify_Date
-- FROM         sys.columns AS C INNER JOIN
--                       sys.objects AS O ON C.object_id = O.object_id AND O.type = 'U' AND O.is_ms_shipped = 0 INNER JOIN
--                       sys.types AS T ON C.user_type_id = T.user_type_id LEFT OUTER JOIN
--                       sys.default_constraints AS D ON C.object_id = D.parent_object_id AND C.column_id = D.parent_column_id AND 
--                       C.default_object_id = D.object_id LEFT OUTER JOIN
--                       sys.extended_properties AS PFD ON PFD.class = 1 AND C.object_id = PFD.major_id AND C.column_id = PFD.minor_id LEFT OUTER JOIN
--                       sys.extended_properties AS PTB ON PTB.class = 1 AND PTB.minor_id = 0 AND C.object_id = PTB.major_id LEFT OUTER JOIN
--                           (SELECT     IDXC.object_id, IDXC.column_id, CASE INDEXKEY_PROPERTY(IDXC.[object_id], IDXC.index_id, IDXC.index_column_id, 'IsDescending') 
--                                                    WHEN 1 THEN 'DESC' WHEN 0 THEN 'ASC' ELSE '' END AS Sort, 
--                                                    CASE WHEN IDX.is_primary_key = 1 THEN N'√' ELSE N'' END AS PrimaryKey, IDX.name AS IndexName
--                             FROM          sys.indexes AS IDX INNER JOIN
--                                                    sys.index_columns AS IDXC ON IDX.object_id = IDXC.object_id AND IDX.index_id = IDXC.index_id LEFT OUTER JOIN
--                                                    sys.key_constraints AS KC ON IDX.object_id = KC.parent_object_id AND IDX.index_id = KC.unique_index_id INNER JOIN
--                                                        (SELECT     object_id, column_id, MIN(index_id) AS index_id
--                                                          FROM          sys.index_columns
--                                                          GROUP BY object_id, column_id) AS IDXCUQ ON IDXC.object_id = IDXCUQ.object_id AND IDXC.column_id = IDXCUQ.column_id AND 
--                                                    IDXC.index_id = IDXCUQ.index_id) AS IDX_1 ON C.object_id = IDX_1.object_id AND C.column_id = IDX_1.column_id
-- ORDER BY TableName, Column_id
-- 
-- ;

-- ----------------------------------------------------------------------------
-- View Mutil_TexasPoker.sp_UpdateNotSendMoney
-- ----------------------------------------------------------------------------
-- USE `Mutil_TexasPoker`;
-- 
-- 
-- 
-- -- =============================================
-- -- Author:		peng cheng long
-- -- Create date: 2012-12-31
-- -- Description:	更新没有发送成功的盈利
-- -- =============================================
-- CREATE  OR REPLACE PROCEDURE [dbo].[sp_UpdateNotSendMoney]
--     @ServerId int,
-- 	@NotSendMoney float
-- AS
-- BEGIN
-- 	SET NOCOUNT OFF;
--     UPDATE   dbo.t_ServerList SET NotSendMoney=@NotSendMoney WHERE ServerId=@ServerId
-- END
-- 
-- 
-- ;

-- ----------------------------------------------------------------------------
-- View Mutil_TexasPoker.sp_AddSendMoney
-- ----------------------------------------------------------------------------
-- USE `Mutil_TexasPoker`;
-- 
-- 
-- 
-- -- =============================================
-- -- Author:		peng cheng long
-- -- Create date: 2012-12-31
-- -- Description:	增加发送成功的盈利
-- -- =============================================
-- CREATE  OR REPLACE PROCEDURE [dbo].[sp_AddSendMoney]
--     @ServerId int,
-- 	@SendMoney float,
-- 	@NotSendMoney float
-- AS
-- BEGIN
-- 	SET NOCOUNT OFF;
--     UPDATE  dbo.t_ServerList SET  SendMoney=SendMoney+@SendMoney,NotSendMoney=@NotSendMoney WHERE ServerId=@ServerId
-- END
-- 
-- 
-- ;

-- ----------------------------------------------------------------------------
-- View Mutil_TexasPoker.sp_GetConfig
-- ----------------------------------------------------------------------------
-- USE `Mutil_TexasPoker`;
-- 
-- -- =============================================
-- -- Author:		peng cheng long
-- -- Create date: 2012-12-6
-- -- Description:	系统全局的配置
-- -- =============================================
-- CREATE  OR REPLACE PROCEDURE [dbo].[sp_GetConfig]
--     @Ckey varchar(50)
-- AS
-- BEGIN
-- 	SET NOCOUNT ON;	
--     DECLARE @STRSQL NVARCHAR(100)
--     SET @STRSQL=N'SELECT Ckey,Cvalue,FValue FROM t_Config'
-- 	if @Ckey  IS NOT NULL AND @Ckey != ''
-- 		BEGIN
-- 			  SET @STRSQL=@STRSQL+N' WHERE Ckey='''+@Ckey+''''
-- 		END
-- 	BEGIN TRANSACTION
-- 	EXECUTE sp_executesql @strsql
--     COMMIT TRANSACTION
-- 	
-- END
-- ;

-- ----------------------------------------------------------------------------
-- View Mutil_TexasPoker.sp_AddCornucopias
-- ----------------------------------------------------------------------------
-- USE `Mutil_TexasPoker`;
-- 
-- 
-- -- =============================================
-- -- Author:		peng cheng long
-- -- Create date: 2012-125
-- -- Description:	增加一条积宝记录,同时更新系统积宝与系统盈利
-- -- =============================================
-- CREATE  OR REPLACE PROCEDURE [dbo].[sp_AddCornucopias]
-- 	@ServerId int,
--     @RoomId int,
--     @GameId int,
--     @UserId int,
--     @idx int,
--     @NickName varchar(20),
--     @WinMoney float,
--     @CardType int,
--     @MaxCards varchar(20)
-- AS
-- BEGIN
-- 	SET NOCOUNT ON;
-- 	BEGIN TRANSACTION
--     INSERT INTO Bonus_GameServerLog(ServerId,RoomId,GameId,UserId,idx,NickName,WinMoney,CardType,MaxCards,WinTime) VALUES(@ServerId,@RoomId,@GameId,@UserId,@idx,@NickName,@WinMoney,@CardType,@MaxCards,getdate())
-- 	IF @@ERROR <> 0
-- 			BEGIN
-- 			 ROLLBACK TRANSACTION
-- 			 RETURN 1
-- 			END    
--     UPDATE t_Config set FValue=FValue-@WinMoney  WHERE CKey='Cornucopia';
--   	IF @@ERROR <> 0
-- 			BEGIN
-- 			 ROLLBACK TRANSACTION
-- 			 RETURN 1
-- 			END
--     COMMIT TRANSACTION
--  RETURN 0
-- END
-- 
-- ;

-- ----------------------------------------------------------------------------
-- View Mutil_TexasPoker.sp_UpdateUser
-- ----------------------------------------------------------------------------
-- USE `Mutil_TexasPoker`;
-- 
-- -- =============================================
-- -- Author:		peng cheng long
-- -- Create date: 2012-12-7
-- -- Description:	当玩家登陆的时候更新状态
-- -- =============================================
-- CREATE  OR REPLACE PROCEDURE [dbo].[sp_UpdateUser]
--        @UserId int,
--        @ServerId int,
--        @CurrentState int ,
--        @LastLoginIp varchar(50),
--        @CurrentServerId int
-- AS
-- BEGIN
-- 	SET NOCOUNT ON;
--      UPDATE  dbo.PlayerInfo SET  ServerId=@ServerId,CurrentState=@CurrentState,LastLoginTime=getdate(),LastLoginIp=@LastLoginIp,CurrentServerId=@CurrentServerId  Where UserId=@UserId 
--     	IF @@ERROR <> 0
-- 			BEGIN
-- 			 RETURN 1
-- 		    END  
--  RETURN 0
-- END
-- 
-- ;

-- ----------------------------------------------------------------------------
-- View Mutil_TexasPoker.sp_Select
-- ----------------------------------------------------------------------------
-- USE `Mutil_TexasPoker`;
-- 
-- -- =============================================
-- -- Author:		peng cheng long
-- -- Create date: 2012-125
-- -- Description:	查询表存储过程，不带分页
-- -- =============================================
-- CREATE  OR REPLACE PROCEDURE [dbo].[sp_Select]	
-- 	@strTableName varchar(100) = '',
-- 	@strWhere varchar(500) = '',
-- 	@strSelectColumns varchar(1000) = '*',	
-- 	@orderby varchar(400) = ''
-- AS
-- BEGIN
-- 	SET NOCOUNT ON;	
--        IF @strTableName IS NULL OR @strTableName=''
--         BEGIN
--          RETURN 1
--         END
-- 	   declare @strsql nvarchar(500)
-- 	   set @strsql = N'select '+@strSelectColumns+' from '+ @strTableName +' '+ @strWhere +' '+@orderby		
-- 	   EXECUTE sp_executesql @strsql
-- END
-- ;

-- ----------------------------------------------------------------------------
-- View Mutil_TexasPoker.sp_UpdateCornucopiaPerSeconds
-- ----------------------------------------------------------------------------
-- USE `Mutil_TexasPoker`;
-- 
-- -- =============================================
-- -- Author:		peng cheng long
-- -- Create date: 2012-12-10
-- -- Description:	定时器更新积宝,传入需要更改的偏移量
-- -- =============================================
-- CREATE  OR REPLACE PROCEDURE [dbo].[sp_UpdateCornucopiaPerSeconds] 
-- 	@TotalOffsetCornucopia float=0
-- AS
-- BEGIN
-- 	SET NOCOUNT ON;
--     ---如果偏移量大于中心服需要偏移的，更新两个全局数据
--     IF EXISTS(SELECT * FROM t_Config WHERE CKey='OffSetCornucopia' AND FValue>=@TotalOffsetCornucopia)
--       BEGIN
--          UPDATE t_Config SET FValue=FValue-@TotalOffsetCornucopia WHERE  CKey='OffSetCornucopia'
--          UPDATE t_Config SET FValue=FValue+@TotalOffsetCornucopia WHERE  CKey='Cornucopia'
--          SELECT FValue AS FROMCornucopia,@TotalOffsetCornucopia AS OffsetCornucopia FROM t_Config WHERE CKey='Cornucopia'
--       END
--     ELSE
--       BEGIN
--       ---如果偏移量小于中心服需要偏移的，不改数据
--          SELECT FValue AS FROMCornucopia,0 AS OffsetCornucopia FROM t_Config WHERE CKey='Cornucopia'
--       END
-- END
-- 
-- ;

-- ----------------------------------------------------------------------------
-- View Mutil_TexasPoker.sp_SynCornucopiaToDb
-- ----------------------------------------------------------------------------
-- USE `Mutil_TexasPoker`;
-- 
-- -- =============================================
-- -- Author:		long
-- -- Create date: 2012-12-10
-- -- Description:	中心服务器定时更新内存的积宝数据
-- -- =============================================
-- CREATE  OR REPLACE PROCEDURE [dbo].[sp_SynCornucopiaToDb]
-- 	@Cornucopia float, 
-- 	@OffSetCornucopia float,
-- 	@SystemTotalWin float
-- AS
-- BEGIN
-- 	SET NOCOUNT ON;
-- 	BEGIN TRANSACTION
--     UPDATE t_Config set FValue=@OffSetCornucopia  WHERE CKey='OffSetCornucopia';
--     	IF @@ERROR <> 0
-- 			BEGIN
-- 			 ROLLBACK TRANSACTION
-- 			 RETURN 1
-- 			END
--     UPDATE t_Config set FValue=@Cornucopia WHERE CKey='Cornucopia';
--   	IF @@ERROR <> 0
-- 			BEGIN
-- 			 ROLLBACK TRANSACTION
-- 			 RETURN 1
-- 			END
--  UPDATE t_Config set FValue=@SystemTotalWin WHERE CKey='SystemTotalWin';
--   	IF @@ERROR <> 0
-- 			BEGIN
-- 			 ROLLBACK TRANSACTION
-- 			 RETURN 1
-- 			END
--     COMMIT TRANSACTION
--  RETURN 0
-- END
-- ;

-- ----------------------------------------------------------------------------
-- View Mutil_TexasPoker.sp_AddGameLog
-- ----------------------------------------------------------------------------
-- USE `Mutil_TexasPoker`;
-- 
-- -- =============================================
-- -- Author:		<Author,,Name>
-- -- Create date: <Create Date,,>
-- -- Description:	<Description,,>
-- -- =============================================
-- CREATE  OR REPLACE PROCEDURE [dbo].[sp_AddGameLog] 
-- @GameId int,
-- @ServerId int,
-- @Step int,
-- @UserId int,
-- @idx int,
-- @SeatId int,
-- @RoundNum int,
-- @ActionType tinyint,
-- @LeftTime int,
-- @GiveChip float,
-- @SiteChip float,
-- @Stake float,
-- @TotalChip float,
-- @CurrentState tinyint,
-- @Memo varchar(50)	
-- AS
-- BEGIN
--  SET NOCOUNT OFF;
--  INSERT INTO [Mutil_TexasPoker].[dbo].[Game_StepLog](GameId,ServerId,Step,UserId,idx,SeatId,RoundNum,ActionType,LeftTime,GiveChip,SiteChip,Stake,TotalChip,CurrentState,CreateTime,Memo)VALUES(@GameId,@ServerId,@Step,@UserId,@idx,@SeatId,@RoundNum,@ActionType,@LeftTime,@GiveChip,@SiteChip,@Stake,@TotalChip,@CurrentState,GETDATE(),@Memo) 
-- END
-- 
-- ;

-- ----------------------------------------------------------------------------
-- View Mutil_TexasPoker.sp_AddCornucopiasRecord
-- ----------------------------------------------------------------------------
-- USE `Mutil_TexasPoker`;
-- 
-- 
-- -- =============================================
-- -- Author:		peng cheng long
-- -- Create date: 2012-125
-- -- Description:	中心服定时批量增加积宝记录
-- -- =============================================
-- CREATE  OR REPLACE PROCEDURE [dbo].[sp_AddCornucopiasRecord]
-- 	@CornucopiaCallBack varchar(20),
-- 	@CornucopiaType tinyint,
-- 	@IsAllow bit=0,
-- 	@IsUsing bit=0,
-- 	@IsSend bit=0,
-- 	@ServerId int,
--     @RoomId int,
--     @GameId int,
--     @SeatId int,
--     @UserId int,
--     @idx int,
--     @NickName varchar(20),
--     @WinMoney int,
--     @CardType int,
--     @MaxCards varchar(20)
-- AS
-- BEGIN
-- 	SET NOCOUNT OFF;
--     INSERT INTO Bonus_CenterServerLog(CornucopiaCallBack,CornucopiaType,IsAllow,IsSend,IsUsing,ServerId,RoomId,GameId,SeatId,UserId,idx,NickName,WinMoney,CardType,MaxCards,WinTime) VALUES(@CornucopiaCallBack,@CornucopiaType,@IsAllow,@IsUsing,@IsSend,@ServerId,@RoomId,@GameId,@SeatId,@UserId,@idx,@NickName,@WinMoney,@CardType,@MaxCards,getdate())
-- END
-- 
-- ;

-- ----------------------------------------------------------------------------
-- View Mutil_TexasPoker.sp_AddTableLog
-- ----------------------------------------------------------------------------
-- USE `Mutil_TexasPoker`;
-- 
-- 
-- 
-- 
-- -- =============================================
-- -- Author:		long
-- -- Create date: 2013-1-21
-- -- Description:	add table log
-- -- =============================================
-- CREATE  OR REPLACE PROCEDURE [dbo].[sp_AddTableLog] 
-- @ServerId  int ,
-- @RoomdId int ,
-- @SeatId  int ,
-- @GameId  int ,
-- @UserId int ,
-- @idx int ,
-- @Money  float ,
-- @Stake float ,
-- @LeftMoney float ,
-- @Win float ,
-- @Memo varchar(50)	
-- AS
-- BEGIN
--  SET NOCOUNT OFF;
--  INSERT INTO Game_TableLog (ServerId ,RoomdId,SeatId ,GameId ,UserId,idx,[Money] ,Stake,LeftMoney,Win,CreateTime,Memo)VALUES(@ServerId ,@RoomdId,@SeatId ,@GameId ,@UserId,@idx,@Money ,@Stake,@LeftMoney,@Win,GETDATE(),@Memo) 
-- END
-- 
-- 
-- 
-- 
-- ;

-- ----------------------------------------------------------------------------
-- View Mutil_TexasPoker.sp_UpdatePlayer
-- ----------------------------------------------------------------------------
-- USE `Mutil_TexasPoker`;
-- 
-- 
-- 
-- -- =============================================
-- -- Author:		long
-- -- Create date: 2013-1-21
-- -- Description:	add table log
-- -- =============================================
-- CREATE  OR REPLACE PROCEDURE [dbo].[sp_UpdatePlayer] 
-- @UserId int ,
-- @Money  float ,
-- @Stake float ,
-- @GameBet float 
-- AS
-- BEGIN
--  SET NOCOUNT OFF;
--  UPDATE  PlayerInfo SET MONEY=@Money,STAKE=@Stake,GameBet=@GameBet WHERE userid=@UserId
-- END
-- 
-- 
-- ;

-- ----------------------------------------------------------------------------
-- View Mutil_TexasPoker.sp_AddBonus_CenterServerLog
-- ----------------------------------------------------------------------------
-- USE `Mutil_TexasPoker`;
-- 
-- 
-- 
-- -- =============================================
-- -- Author:		peng cheng long
-- -- Create date: 2013-1-22
-- -- Description:	中心服积宝记录
-- -- =============================================
-- CREATE  OR REPLACE PROCEDURE [dbo].[sp_AddBonus_CenterServerLog]
-- 	@CornucopiaCallBack varchar(20),
-- 	@CornucopiaType tinyint,
-- 	@IsAllow bit=0,
-- 	@IsUsing bit=0,
-- 	@IsSend bit=0,
-- 	@ServerId int,
--     @RoomId int,
--     @GameId int,
--     @SeatId int,
--     @UserId int,
--     @idx int,
--     @NickName varchar(20),
--     @WinMoney int,
--     @CardType int,
--     @MaxCards varchar(20)
-- AS
-- BEGIN
-- 	SET NOCOUNT OFF;
--     INSERT INTO Bonus_CenterServerLog(CornucopiaCallBack,CornucopiaType,IsAllow,IsSend,IsUsing,ServerId,RoomId,GameId,SeatId,UserId,idx,NickName,WinMoney,CardType,MaxCards,WinTime) VALUES(@CornucopiaCallBack,@CornucopiaType,@IsAllow,@IsUsing,@IsSend,@ServerId,@RoomId,@GameId,@SeatId,@UserId,@idx,@NickName,@WinMoney,@CardType,@MaxCards,getdate())
-- END
-- 
-- 
-- ;

-- ----------------------------------------------------------------------------
-- View Mutil_TexasPoker.sp_AddBonus_GameServerLog
-- ----------------------------------------------------------------------------
-- USE `Mutil_TexasPoker`;
-- 
-- 
-- 
-- -- =============================================
-- -- Author:		peng cheng long
-- -- Create date: 2013-1-22
-- -- Description:	中心服积宝记录
-- -- =============================================
-- CREATE  OR REPLACE PROCEDURE [dbo].[sp_AddBonus_GameServerLog]
-- 	@CornucopiaCallBack varchar(20),
-- 	@CornucopiaType tinyint,
-- 	@IsUsing bit=0,
-- 	@IsSend bit=0,
-- 	@ServerId int,
--     @RoomId int,
--     @GameId int,
--     @SeatId int,
--     @UserId int,
--     @idx int,
--     @NickName varchar(20),
--     @WinMoney int,
--     @CardType int,
--     @MaxCards varchar(20),
--     @Memo varchar(50)
-- AS
-- BEGIN
-- 	SET NOCOUNT OFF;
--     INSERT INTO Bonus_GameServerLog(CornucopiaCallBack,CornucopiaType,IsUsing,IsSend,ServerId,RoomId,GameId,SeatId,UserId,idx,NickName,WinMoney,CardType,MaxCards,WinTime,Memo) VALUES(@CornucopiaCallBack,@CornucopiaType,@IsUsing,@IsSend,@ServerId,@RoomId,@GameId,@SeatId,@UserId,@idx,@NickName,@WinMoney,@CardType,@MaxCards,getdate(),@Memo)
-- END
-- 
-- 
-- ;

-- ----------------------------------------------------------------------------
-- View Mutil_TexasPoker.sp_GetUserInfo
-- ----------------------------------------------------------------------------
-- USE `Mutil_TexasPoker`;
-- 
-- 
-- -- =============================================
-- -- Author:		peng cheng long
-- -- Create date: 2013-1-23
-- -- Description:	玩家首次登陆，获得此人详细信息
-- -- =============================================
-- CREATE  OR REPLACE PROCEDURE [dbo].[sp_GetUserInfo]
--     @UserName varchar(50),
--     @ServerId int
-- AS
-- BEGIN
-- 	SET NOCOUNT ON;	
--     SELECT UserId,GameBet,Stake,NickName,HeadImage,Sex,RealName,Icon,RankMoney,PlayCount,WinCount,MaxMoney,MaxHandCard,MaxWin,CurrentState FROM PlayerInfo WHERE  UserName=@UserName and ServerId=@ServerId	
-- END
-- 
-- ;

-- ----------------------------------------------------------------------------
-- View Mutil_TexasPoker.sp_ServerLogoff
-- ----------------------------------------------------------------------------
-- USE `Mutil_TexasPoker`;
-- 
--  
-- 
-- -- =============================================
-- -- Author:		peng cheng long
-- -- Create date: 2013-1-24
-- -- Description:	服务器注销
-- -- =============================================
-- CREATE  OR REPLACE PROCEDURE [dbo].[sp_ServerLogoff]
--     @ServerId int
-- AS
-- BEGIN
-- 	SET NOCOUNT ON;	
--     UPDATE dbo.t_ServerList SET State=0,LastLogOutTime=GETDATE() WHERE ServerId=@ServerId
--     RETURN @@ROWCOUNT    
-- END
-- 
-- 
-- ;

-- ----------------------------------------------------------------------------
-- View Mutil_TexasPoker.sp_ServerLogin
-- ----------------------------------------------------------------------------
-- USE `Mutil_TexasPoker`;
-- 
-- 
-- 
--  
-- 
-- -- =============================================
-- -- Author:		peng cheng long
-- -- Create date: 2013-1-23
-- -- Description:	服务器登录
-- -- =============================================
-- CREATE  OR REPLACE PROCEDURE [dbo].[sp_ServerLogin]
--     @ServerId int,
--     @ServerIp varchar(50)
-- AS
-- BEGIN
-- 	SET NOCOUNT ON;	
--     UPDATE dbo.t_ServerList SET State=1,LastLoginTime=GETDATE() WHERE ServerId=@ServerId AND ServerIp=@ServerIp AND State !=1
--     RETURN @@ROWCOUNT    
-- END
-- 
-- 
-- 
-- 
-- ;

-- ----------------------------------------------------------------------------
-- View Mutil_TexasPoker.sp_ClearServerLogin
-- ----------------------------------------------------------------------------
-- USE `Mutil_TexasPoker`;
-- 
-- 
-- 
--  
-- 
-- -- =============================================
-- -- Author:		peng cheng long
-- -- Create date: 2013-1-24
-- -- Description:	清除所有服务器登录
-- -- =============================================
-- CREATE  OR REPLACE PROCEDURE [dbo].[sp_ClearServerLogin]
-- AS
-- BEGIN
-- 	SET NOCOUNT ON;	
--     UPDATE dbo.t_ServerList SET State=0
--     IF @@ROWCOUNT<>0
--        BEGIN    
--         RETURN 1
--        END
--     RETURN 0
-- END
-- 
-- 
-- ;

-- ----------------------------------------------------------------------------
-- View Mutil_TexasPoker.sp_AddPlayMoneyLog
-- ----------------------------------------------------------------------------
-- USE `Mutil_TexasPoker`;
-- 
-- 
-- 
-- 
-- 
-- -- =============================================
-- -- Author:		peng cheng long
-- -- Create date: 2012-12-12
-- -- Description:	增加一条游戏下注了钱,游戏结束赢输钱
-- -- =============================================
-- CREATE  OR REPLACE PROCEDURE [dbo].[sp_AddPlayMoneyLog]
--     @UserId int,
--     @idx int,
-- 	@Bet float,
--     @Win float,
--     @stake float
-- AS
-- BEGIN
-- 	SET NOCOUNT OFF;
--     INSERT INTO AccountMoneyLog(UserId,idx,Bet,Win,CreateTime) VALUES(@UserId,@idx,@Bet,@Win,getdate())
--     --SAVE TEMP BET ,WHEN GAME OVER,CLEAR
--     IF  @Bet>0
--      BEGIN
--       UPDATE dbo.PlayerInfo SET GameBet=GameBet+@Bet,Stake=@stake  WHERE UserId=@UserId
--      END  
-- END
-- 
-- 
-- 
-- 
-- ;

-- ----------------------------------------------------------------------------
-- View Mutil_TexasPoker.sp_SaveGameWinner
-- ----------------------------------------------------------------------------
-- USE `Mutil_TexasPoker`;
-- 
-- 
-- 
-- 
-- 
-- -- =============================================
-- -- Author:		long
-- -- Create date: 2013-1-28
-- -- Description:	保存游戏结束时候玩家的输赢情况，同时更新账号筹码下注
-- -- =============================================
-- CREATE  OR REPLACE PROCEDURE [dbo].[sp_SaveGameWinner] 
-- @ServerId  int ,
-- @RoomdId int ,
-- @SeatId  int ,
-- @GameId  int ,
-- @UserId int ,
-- @idx int ,
-- @Money  float ,
-- @Stake float ,
-- @LeftMoney float ,
-- @Win float ,
-- @Memo varchar(50)	
-- AS
-- BEGIN
--  SET NOCOUNT OFF;
--  INSERT INTO Game_TableLog (ServerId ,RoomdId,SeatId ,GameId ,UserId,idx,[Money] ,Stake,LeftMoney,Win,CreateTime,Memo)VALUES(@ServerId ,@RoomdId,@SeatId ,@GameId ,@UserId,@idx,@Money ,@Stake,@LeftMoney,@Win,GETDATE(),@Memo) 
--   IF @@ROWCOUNT<>1
--      BEGIN
--       RETURN 0
--      END
--   UPDATE  PlayerInfo SET MONEY=@Money,STAKE=@Stake,GameBet=0 WHERE userid=@UserId
--   RETURN @@ROWCOUNT
-- END
-- 
-- 
-- 
-- 
-- 
-- ;

-- ----------------------------------------------------------------------------
-- View Mutil_TexasPoker.sp_UpdateUserHeadImage
-- ----------------------------------------------------------------------------
-- USE `Mutil_TexasPoker`;
-- 
-- 
-- -- =============================================
-- -- Author:		peng cheng long
-- -- Create date: 2012-12-18
-- -- Description:	更新玩家头像
-- -- =============================================
-- CREATE  OR REPLACE PROCEDURE [dbo].[sp_UpdateUserHeadImage]
--     @UserId int,
-- 	@HeadImage image
-- AS
-- BEGIN
-- 	SET NOCOUNT OFF;
--     UPDATE  dbo.PlayerInfo SET HeadImage=@HeadImage WHERE USERID=@UserId
-- END
-- 
-- ;

-- ----------------------------------------------------------------------------
-- View Mutil_TexasPoker.sp_AddEndGameLog
-- ----------------------------------------------------------------------------
-- USE `Mutil_TexasPoker`;
-- 
-- 
-- 
-- 
-- -- =============================================
-- -- Author:		long
-- -- Create date: 2012-12-20
-- -- Description:	游戏结束，分配边池的钱，系统抽成
-- -- =============================================
-- CREATE  OR REPLACE PROCEDURE [dbo].[sp_AddEndGameLog]
-- 	@GameId int, 
--     @BonusPools varchar(50),
--     @SystemWinPools varchar(50),
--     @SystemWin float,
--     --转换多少积宝由中心服控制@ToCornucopia int,
--     @Winners varchar(50),
--     @idx_win varchar(200),
--     @WinMoneys varchar(50),
--     @MaxHands varchar(100)
-- AS
-- BEGIN
-- 	SET NOCOUNT OFF
-- 		INSERT INTO Game_EndLog 
--            ([GameId],[BonusPools]
--            ,[SystemWinPools]
--            ,[SystemWin]        
--            ,[Winners]
--            ,[idx_win]
--            ,[WinMoneys]
--            ,[MaxHands]
--            ,[EndTime])
--         VALUES(@GameId,@BonusPools,@SystemWinPools,@SystemWin,@Winners,@idx_win,@WinMoneys,@MaxHands,getdate());
-- END
-- 
-- 
-- 
-- ;

-- ----------------------------------------------------------------------------
-- View Mutil_TexasPoker.sp_AddBeginGameLog
-- ----------------------------------------------------------------------------
-- USE `Mutil_TexasPoker`;
-- 
-- 
-- 
-- 
-- 
-- 
-- -- =============================================
-- -- Author:		peng cheng long
-- -- Create date: 2012-12-12
-- -- Description:	增加一条游戏开始的记录
-- -- =============================================
-- CREATE  OR REPLACE PROCEDURE [dbo].[sp_AddBeginGameLog]
--     @ServerId int,
-- 	@RoomId int,
-- 	@RoomCode int,
--     @RoomName varchar(50),
--     @PlayerNum int,
--     @SeatCount int,
--     @prevId int,
--     @PublicCard varchar(50),
--     @SeatUserIds varchar(100),
--     @SeatIdx varchar(200),
--     @DealerId int,
--     @MinBindUserId int,
--     @MinBind int,
--     @MaxBindUserId int,
--     @MaxBind int,
--     @DlayTime int,
--     @MinStake int,
--     @MaxStake int,
--     @NewChip int,
--     @NewUserIds varchar(50),
--     @WatchUserIds varchar(50),
--     @StartChips varchar(50),
--     @SeatUserId1 int,
--     @SeatUserId2 int,
--     @SeatUserId3 int,
--     @SeatUserId4 int,
--     @SeatUserId5 int,
--     @SeatUserId6 int,
--     @SeatUserId7 int,
--     @SeatUserId8 int,
--     @SeatUserId9 int,
-- @HandCard1 varchar(50),
-- @HandCard2 varchar(50),
-- @HandCard3 varchar(50),
-- @HandCard4 varchar(50),
-- @HandCard5 varchar(50),
-- @HandCard6 varchar(50),
-- @HandCard7 varchar(50),
-- @HandCard8 varchar(50),
-- @HandCard9 varchar(50),
-- @PokerIndexs varchar(200)
-- AS
-- BEGIN
-- 	SET NOCOUNT ON;
--     INSERT INTO dbo.Game_BeginLog(ServerId,RoomId,RoomCode,RoomName,PlayerNum,SeatCount,prevId,PublicCard,SeatUserIds,SeatIdx,DealerId,MinBindUserId,MinBind,MaxBindUserId,MaxBind,DlayTime,MinStake,MaxStake,NewChip,NewUserIds,WatchUserIds,StartChips,SeatUserId1,SeatUserId2,SeatUserId3,SeatUserId4,SeatUserId5,SeatUserId6,SeatUserId7,SeatUserId8,SeatUserId9,HandCard1,HandCard2,HandCard3,HandCard4,HandCard5,HandCard6,HandCard7,HandCard8,HandCard9,PokerIndexs,StartTime)  VALUES(@ServerId,@RoomId,@RoomCode,@RoomName,@PlayerNum,@SeatCount,@prevId,@PublicCard,@SeatUserIds,@SeatIdx,@DealerId,@MinBindUserId,@MinBind,@MaxBindUserId,@MaxBind,@DlayTime,@MinStake,@MaxStake,@NewChip,@NewUserIds,@WatchUserIds,@StartChips,@SeatUserId1,@SeatUserId2,@SeatUserId3,@SeatUserId4,@SeatUserId5,@SeatUserId6,@SeatUserId7,@SeatUserId8,@SeatUserId9,@HandCard1,@HandCard2,@HandCard3,@HandCard4,@HandCard5,@HandCard6,@HandCard7,@HandCard8,@HandCard9,@PokerIndexs,getdate())
--     ; select SCOPE_IDENTITY()
-- END
-- 
-- 
-- 
-- 
-- 
-- ;

-- ----------------------------------------------------------------------------
-- View Mutil_TexasPoker.sp_AddSynMoneyLog
-- ----------------------------------------------------------------------------
-- USE `Mutil_TexasPoker`;
-- 
-- -- =============================================
-- -- Author:		long
-- -- Create date: 2012-12-11
-- -- Description:	中心服务器定时更新内存的积宝数据,同时保存同步记录
-- -- =============================================
-- CREATE  OR REPLACE PROCEDURE [dbo].[sp_AddSynMoneyLog]
-- 	@IsSynSuc bit=0, 
-- 	@SynCornucopia float, 
-- 	@SynOffSetCornucopia float,
-- 	@SynSystemTotalWin float
-- AS
-- BEGIN
-- 	SET NOCOUNT ON;
-- 	BEGIN TRANSACTION
--     INSERT INTO [Db_Wandian_Log].[dbo].[t_SynMoneyLog]([isSynSuc] ,[SynCornucopia] ,[SynOffSetCornucopia]  ,[SynSystemTotalWin],[SynTime])
--          VALUES
--            (@IsSynSuc
--            ,@SynCornucopia
--            ,@SynOffSetCornucopia
--            ,@SynSystemTotalWin
--            ,getdate())
--     	IF @@ERROR <> 0
-- 			BEGIN
-- 			 ROLLBACK TRANSACTION
-- 			 RETURN 1
-- 			END
--     COMMIT TRANSACTION
--  RETURN 0
-- END
-- ;

-- ----------------------------------------------------------------------------
-- View Mutil_TexasPoker.sp_AddUserInfo
-- ----------------------------------------------------------------------------
-- USE `Mutil_TexasPoker`;
-- 
-- 
-- 
-- 
-- 
-- -- =============================================
-- -- Author:		peng cheng long
-- -- Create date: 2012-12-27
-- -- Description:	user login texas poker first time ,import info from accounttable,initailize base info
-- -- =============================================
-- CREATE  OR REPLACE PROCEDURE [dbo].[sp_AddUserInfo]
-- 	@idx int,
--     @ServerId int,
--     @UserName varchar(50),
--     @NickName varchar(50),
--     @Sex bit,
--     @Icon varchar(50)
-- AS
-- BEGIN
-- 	SET NOCOUNT ON
--     INSERT INTO PlayerInfo(idx,ServerId,UserName,NickName,Sex,Icon,CreateDate)VALUES(@idx,@ServerId,@UserName,@NickName,@Sex,@Icon,GETDATE())
--     ; select SCOPE_IDENTITY()
-- END
-- 
-- 
-- 
-- 
-- ;

-- ----------------------------------------------------------------------------
-- View Mutil_TexasPoker.sp_GetFriendList
-- ----------------------------------------------------------------------------
-- USE `Mutil_TexasPoker`;
-- 
-- 
-- -- =============================================
-- -- Author:		<long>
-- -- Create date: <2012-10-25>
-- -- Description:	<根据用户id查找好友列表>
-- -- =============================================
-- CREATE  OR REPLACE PROCEDURE [dbo].[sp_GetFriendList]
-- 	@UserId int
-- AS
-- BEGIN
-- 	SET NOCOUNT ON;
--   Select UserId,NickName,HeadImage,Sex,IsPlaying,CurrentRoomId,Money,Icon From  PlayerInfo where UserId in (
-- Select UserId From t_Friends where friendid=@UserId and state=1
-- union
-- Select friendid From t_Friends where UserId=@UserId and state=1
-- )
-- END
-- 
-- ;

-- ----------------------------------------------------------------------------
-- View Mutil_TexasPoker.Public_InsertAccountMoney
-- ----------------------------------------------------------------------------
-- USE `Mutil_TexasPoker`;
-- 
--  	
-- -- =============================================
-- -- 记录玩家下注记录
-- -- =============================================
-- CREATE  OR REPLACE PROCEDURE [dbo].[Public_InsertAccountMoney] 
-- (
-- @idx int,			-- 玩家账户ID
-- @bet float,			-- 玩家下注额
-- @win float			-- 玩家赢额
-- )
-- AS
-- SET NOCOUNT ON;
-- 	insert into Public_AccountMoneyLog(idx,bet,win) values (@idx,@bet,@win)
-- 
-- --对他上级代理做账目更新
-- 	declare 
-- 			@acctype	smallint,		--1，11 纯外网玩家账号 2 ，21店内玩家账号
-- 			@Account	varchar(17),
-- 			@Manger		varchar(17)  
-- 	select 	@acctype= [TYPE],@Account=Account,@Manger=Agent from LinkDB_Account.AccountDB.dbo.AccountTable where idx = @idx
-- 	if @@ROWCOUNT=0
-- 		begin
-- 			return 0
-- 		end
-- 	
-- 	declare 
-- 			@TempAcc	varchar(17),
-- 			@nowtime	datetime = getdate(),
-- 			@nowDay		int,
-- 			@nowMonth	int,
-- 			@nowYear	int
-- 	set @TempAcc	= @Account
-- 	set @nowDay		= DATEPART(day, @nowtime)
-- 	set @nowMonth	= DATEPART(month,@nowtime)
-- 	set @nowYear	= DATEPART(year,@nowtime)
-- 	
-- 	declare 
-- 		@lastDay	int,
-- 		@lastMonth	int,
-- 		@lastYear	int,
-- 		@no_index	int = 0
-- 		
-- 	if(@acctype <> 2 and @acctype <> 21)----  纯外网玩家账号
-- 	begin
-- 		select @Manger=Agent from LinkDB_Account.AccountDB.dbo.AccountTable where Account = @TempAcc
-- 		while  @@ROWCOUNT <>0 
-- 			begin
-- 				if (@Manger <> 'admin')
-- 				begin
-- 					set @nowtime = '1999-1-1'
-- 					select @nowtime=CreateTime ,@no_index = [index_no]  from Public_AgentMoneyLog where [index_no] =
-- 					(
-- 						select max([index_no])   from Public_AgentMoneyLog where Account = @Manger 
-- 					)
-- 					set @lastDay	=  DATEPART(day, @nowtime)
-- 					set @lastMonth	=  DATEPART(month, @nowtime)
-- 					set @lastYear	=  DATEPART(year,@nowtime)
-- 					if (@nowDay =  @lastDay and @nowMonth = @lastMonth and @nowYear=@lastYear) 
-- 						begin  
-- 							update Public_AgentMoneyLog set bet=bet+@bet,Win = Win+@Win where Account = @Manger and [index_no] = [index_no]
-- 						end
-- 					else 
-- 						begin 
-- 							insert Public_AgentMoneyLog(Account,bet,win) values ( @Manger,@bet,@Win)
-- 						end
-- 					set @TempAcc = @Manger
-- 					select @Manger=Agent from LinkDB_Account.AccountDB.dbo.AccountTable where Account = @TempAcc
-- 				end
-- 				else	
-- 					break;
-- 			end	
-- 	end
-- 	else--店内账号
-- 		begin		    
-- 				if (@Manger <> 'admin')-- 先更新店的账目
-- 					begin
-- 							set @nowtime = '1999-1-1'
-- 							select @nowtime=CreateTime ,@no_index = [index_no]  from Public_AgentMoneyLog where [index_no] =
-- 							(
-- 								select max([index_no])   from Public_AgentMoneyLog where Account = @Manger 
-- 							)
-- 							set @lastDay	=  DATEPART(day, @nowtime)
-- 							set @lastMonth	=  DATEPART(month, @nowtime)
-- 							set @lastYear	=  DATEPART(year,@nowtime)
-- 							if (@nowDay =  @lastDay and @nowMonth = @lastMonth and @nowYear=@lastYear) 
-- 								begin  
-- 									update Public_AgentMoneyLog set bet=bet+@bet,Win = Win+@Win where Account = @Manger and [index_no] = [index_no]
-- 								end
-- 		   					else 
-- 								begin 
-- 									insert Public_AgentMoneyLog(Account,bet,win) values ( @Manger,@bet,@Win)
-- 								end
-- 					end
-- 				else
-- 					return 1
-- 				set @TempAcc = @Manger--在从server_list里面找店的上级代理 
-- 				select @Manger= UserManager from LinkDB_casino.casino_central.dbo.Server_List  where Account = @TempAcc
-- 				while  @@ROWCOUNT <>0 
-- 					begin
-- 						if (@Manger <> 'admin')
-- 							begin
-- 								set @nowtime = '1999-1-1'
-- 								select @nowtime=CreateTime ,@no_index = [index_no]  from Public_AgentMoneyLog where [index_no] =
-- 								(
-- 									select max([index_no])   from Public_AgentMoneyLog where Account = @Manger 
-- 								)
-- 								set @lastDay	=  DATEPART(day, @nowtime)
-- 								set @lastMonth	=  DATEPART(month, @nowtime)
-- 								set @lastYear	=  DATEPART(year,@nowtime)
-- 								if (@nowDay =  @lastDay and @nowMonth = @lastMonth and @nowYear=@lastYear) 
-- 									begin  
-- 										update Public_AgentMoneyLog set bet=bet+@bet,Win = Win+@Win where Account = @Manger and [index_no] = [index_no]
-- 									end
-- 		   						else 
-- 									begin 
-- 										insert Public_AgentMoneyLog(Account,bet,win) values ( @Manger,@bet,@Win)
-- 									end
-- 								set @TempAcc = @Manger
-- 								select @Manger= UserManager from LinkDB_casino.casino_central.dbo.Server_List  where Account = @TempAcc
-- 							end
-- 						else	
-- 							 break;
-- 					end
-- 		end
-- 
-- return 1
-- 	SET NOCOUNT OFF;
-- ;

-- ----------------------------------------------------------------------------
-- Routine Mutil_TexasPoker.sp_AutoAddNum
-- ----------------------------------------------------------------------------
-- DELIMITER $$
-- 
-- DELIMITER $$
-- USE `Mutil_TexasPoker`$$
-- 
-- 
-- 
-- 
-- 
-- 
-- 
-- -- =============================================
-- -- Author:		long
-- -- Create date: 2012-10-14
-- -- Description:	测试数据库number自动增加
-- -- =============================================
-- CREATE PROCEDURE [dbo].[sp_AutoAddNum]
-- 	@Id int
-- AS
-- BEGIN
-- SET NOCOUNT ON;
-- begin transaction
-- 	update t_test  set [count]=[count]+1 where id=@Id;
-- 	Select [count] From t_test where id=@Id
-- commit transaction
-- END
-- 
-- 
-- 
-- 
-- 
-- 
-- 
-- $$
-- 
-- DELIMITER ;
-- 
-- ----------------------------------------------------------------------------
-- Routine Mutil_TexasPoker.sp_AutoAddNum1
-- ----------------------------------------------------------------------------
-- DELIMITER $$
-- 
-- DELIMITER $$
-- USE `Mutil_TexasPoker`$$
-- 
-- 
-- -- =============================================
-- -- Author:		long
-- -- Create date: 2012-10-14
-- -- Description:	测试数据库number自动增加
-- -- =============================================
-- CREATE PROCEDURE [dbo].[sp_AutoAddNum1]
-- 	@Id int,
--     @Result int output
-- AS
-- BEGIN
-- 	Select @Result=[Count] From t_test where id=@Id
-- END
-- 
-- 
-- $$
-- 
-- DELIMITER ;
-- 
-- ----------------------------------------------------------------------------
-- Routine Mutil_TexasPoker.sp_AddPlayMoneyLogWhenError
-- ----------------------------------------------------------------------------
-- DELIMITER $$
-- 
-- DELIMITER $$
-- USE `Mutil_TexasPoker`$$
-- 
-- 
-- 
-- 
-- 
-- -- =============================================
-- -- Author:		peng cheng long
-- -- Create date: 2012-12-29
-- -- Description:	
-- -- =============================================
-- CREATE PROCEDURE [dbo].[sp_AddPlayMoneyLogWhenError]
--     @UserId int,
--     @idx int,
-- 	@Bet float,
--     @Win float
-- AS
-- BEGIN
-- 	SET NOCOUNT OFF;
--     INSERT INTO AccountMoneyLog(UserId,idx,Bet,Win,CreateTime) VALUES(@UserId,@idx,@Bet,@Win,getdate())   
--     UPDATE dbo.PlayerInfo SET GameBet=0 WHERE UserId=@UserId
-- END
-- 
-- 
-- 
-- 
-- $$
-- 
-- DELIMITER ;
-- 
-- ----------------------------------------------------------------------------
-- Routine Mutil_TexasPoker.sp_Pagination
-- ----------------------------------------------------------------------------
-- DELIMITER $$
-- 
-- DELIMITER $$
-- USE `Mutil_TexasPoker`$$
-- 
-- -- =============================================
-- -- Author:		peng cheng long
-- -- Create date: 2012-125
-- -- Description:	分页存储过程
-- -- =============================================
-- CREATE PROCEDURE [dbo].[sp_Pagination]	
-- 	@strTableName varchar(2000) = '',
-- 	@strWhere varchar(500) = '',
-- 	@strSelectColumns varchar(1000) = '*',
-- 	@currentPage int=1,
-- 	@pageSize int =12,
-- 	@orderby varchar(400) = '',
-- 	@PKName varchar(50) = 'Id',
-- 	@total int output
-- AS
-- BEGIN
-- 	-- SET NOCOUNT ON added to prevent extra result sets from
-- 	-- interfering with SELECT statements.
-- 	SET NOCOUNT ON;
-- 	declare @startRow int
-- 	declare @endRow int
-- 	declare @strsql nvarchar(4000)
-- 
-- 	set @strsql = 'select @total= count('+@PKName+') from ' + @strTableName + ' ' + @strWhere
-- 
-- 	exec sp_executesql @strsql,N'@total int output',@total output
-- 	
-- 	if @orderby is null or @orderby = ''
-- 		begin
-- 			set @orderby='Order by '+@PKName
-- 		end
-- 	
-- 	if @currentPage >0 and @pageSize >0
-- 	begin
-- 		set @startRow = (@currentPage-1) * @pageSize 
-- 		set @endRow = @currentPage * @pageSize
-- 
-- 		set @strsql = N'select * from (select ROW_NUMBER() OVER ('+@orderby+') AS RowNum ,'+@strSelectColumns+' from '+ @strTableName +' '+ 
-- 		@strWhere +') as mainTable Where mainTable.RowNum>'+Convert(varchar(15),@startRow)+' and mainTable.RowNum<='+Convert(varchar(15),@endRow)
-- 		
-- 	end
-- 	else 
-- 		set @strsql = N'select * from (select ROW_NUMBER() OVER ('+@orderby+') AS RowNum ,'+@strSelectColumns+' from '+ @strTableName +' '+ @strWhere +') as mainTable'
-- 		
-- 		EXECUTE sp_executesql @strsql
-- 
-- 		
-- 		--
-- 	--select @strsql
-- END
-- $$
-- 
-- DELIMITER ;
-- 
-- ----------------------------------------------------------------------------
-- Routine Mutil_TexasPoker.sp_UpdateNotSendMoney
-- ----------------------------------------------------------------------------
-- DELIMITER $$
-- 
-- DELIMITER $$
-- USE `Mutil_TexasPoker`$$
-- 
-- 
-- 
-- -- =============================================
-- -- Author:		peng cheng long
-- -- Create date: 2012-12-31
-- -- Description:	更新没有发送成功的盈利
-- -- =============================================
-- CREATE PROCEDURE [dbo].[sp_UpdateNotSendMoney]
--     @ServerId int,
-- 	@NotSendMoney float
-- AS
-- BEGIN
-- 	SET NOCOUNT OFF;
--     UPDATE   dbo.t_ServerList SET NotSendMoney=@NotSendMoney WHERE ServerId=@ServerId
-- END
-- 
-- 
-- $$
-- 
-- DELIMITER ;
-- 
-- ----------------------------------------------------------------------------
-- Routine Mutil_TexasPoker.sp_AddSendMoney
-- ----------------------------------------------------------------------------
-- DELIMITER $$
-- 
-- DELIMITER $$
-- USE `Mutil_TexasPoker`$$
-- 
-- 
-- 
-- -- =============================================
-- -- Author:		peng cheng long
-- -- Create date: 2012-12-31
-- -- Description:	增加发送成功的盈利
-- -- =============================================
-- CREATE PROCEDURE [dbo].[sp_AddSendMoney]
--     @ServerId int,
-- 	@SendMoney float,
-- 	@NotSendMoney float
-- AS
-- BEGIN
-- 	SET NOCOUNT OFF;
--     UPDATE  dbo.t_ServerList SET  SendMoney=SendMoney+@SendMoney,NotSendMoney=@NotSendMoney WHERE ServerId=@ServerId
-- END
-- 
-- 
-- $$
-- 
-- DELIMITER ;
-- 
-- ----------------------------------------------------------------------------
-- Routine Mutil_TexasPoker.sp_GetConfig
-- ----------------------------------------------------------------------------
-- DELIMITER $$
-- 
-- DELIMITER $$
-- USE `Mutil_TexasPoker`$$
-- 
-- -- =============================================
-- -- Author:		peng cheng long
-- -- Create date: 2012-12-6
-- -- Description:	系统全局的配置
-- -- =============================================
-- CREATE PROCEDURE [dbo].[sp_GetConfig]
--     @Ckey varchar(50)
-- AS
-- BEGIN
-- 	SET NOCOUNT ON;	
--     DECLARE @STRSQL NVARCHAR(100)
--     SET @STRSQL=N'SELECT Ckey,Cvalue,FValue FROM t_Config'
-- 	if @Ckey  IS NOT NULL AND @Ckey != ''
-- 		BEGIN
-- 			  SET @STRSQL=@STRSQL+N' WHERE Ckey='''+@Ckey+''''
-- 		END
-- 	BEGIN TRANSACTION
-- 	EXECUTE sp_executesql @strsql
--     COMMIT TRANSACTION
-- 	
-- END
-- $$
-- 
-- DELIMITER ;
-- 
-- ----------------------------------------------------------------------------
-- Routine Mutil_TexasPoker.sp_AddCornucopias
-- ----------------------------------------------------------------------------
-- DELIMITER $$
-- 
-- DELIMITER $$
-- USE `Mutil_TexasPoker`$$
-- 
-- 
-- -- =============================================
-- -- Author:		peng cheng long
-- -- Create date: 2012-125
-- -- Description:	增加一条积宝记录,同时更新系统积宝与系统盈利
-- -- =============================================
-- CREATE PROCEDURE [dbo].[sp_AddCornucopias]
-- 	@ServerId int,
--     @RoomId int,
--     @GameId int,
--     @UserId int,
--     @idx int,
--     @NickName varchar(20),
--     @WinMoney float,
--     @CardType int,
--     @MaxCards varchar(20)
-- AS
-- BEGIN
-- 	SET NOCOUNT ON;
-- 	BEGIN TRANSACTION
--     INSERT INTO Bonus_GameServerLog(ServerId,RoomId,GameId,UserId,idx,NickName,WinMoney,CardType,MaxCards,WinTime) VALUES(@ServerId,@RoomId,@GameId,@UserId,@idx,@NickName,@WinMoney,@CardType,@MaxCards,getdate())
-- 	IF @@ERROR <> 0
-- 			BEGIN
-- 			 ROLLBACK TRANSACTION
-- 			 RETURN 1
-- 			END    
--     UPDATE t_Config set FValue=FValue-@WinMoney  WHERE CKey='Cornucopia';
--   	IF @@ERROR <> 0
-- 			BEGIN
-- 			 ROLLBACK TRANSACTION
-- 			 RETURN 1
-- 			END
--     COMMIT TRANSACTION
--  RETURN 0
-- END
-- 
-- $$
-- 
-- DELIMITER ;
-- 
-- ----------------------------------------------------------------------------
-- Routine Mutil_TexasPoker.sp_UpdateUser
-- ----------------------------------------------------------------------------
-- DELIMITER $$
-- 
-- DELIMITER $$
-- USE `Mutil_TexasPoker`$$
-- 
-- -- =============================================
-- -- Author:		peng cheng long
-- -- Create date: 2012-12-7
-- -- Description:	当玩家登陆的时候更新状态
-- -- =============================================
-- CREATE PROCEDURE [dbo].[sp_UpdateUser]
--        @UserId int,
--        @ServerId int,
--        @CurrentState int ,
--        @LastLoginIp varchar(50),
--        @CurrentServerId int
-- AS
-- BEGIN
-- 	SET NOCOUNT ON;
--      UPDATE  dbo.PlayerInfo SET  ServerId=@ServerId,CurrentState=@CurrentState,LastLoginTime=getdate(),LastLoginIp=@LastLoginIp,CurrentServerId=@CurrentServerId  Where UserId=@UserId 
--     	IF @@ERROR <> 0
-- 			BEGIN
-- 			 RETURN 1
-- 		    END  
--  RETURN 0
-- END
-- 
-- $$
-- 
-- DELIMITER ;
-- 
-- ----------------------------------------------------------------------------
-- Routine Mutil_TexasPoker.sp_Select
-- ----------------------------------------------------------------------------
-- DELIMITER $$
-- 
-- DELIMITER $$
-- USE `Mutil_TexasPoker`$$
-- 
-- -- =============================================
-- -- Author:		peng cheng long
-- -- Create date: 2012-125
-- -- Description:	查询表存储过程，不带分页
-- -- =============================================
-- CREATE PROCEDURE [dbo].[sp_Select]	
-- 	@strTableName varchar(100) = '',
-- 	@strWhere varchar(500) = '',
-- 	@strSelectColumns varchar(1000) = '*',	
-- 	@orderby varchar(400) = ''
-- AS
-- BEGIN
-- 	SET NOCOUNT ON;	
--        IF @strTableName IS NULL OR @strTableName=''
--         BEGIN
--          RETURN 1
--         END
-- 	   declare @strsql nvarchar(500)
-- 	   set @strsql = N'select '+@strSelectColumns+' from '+ @strTableName +' '+ @strWhere +' '+@orderby		
-- 	   EXECUTE sp_executesql @strsql
-- END
-- $$
-- 
-- DELIMITER ;
-- 
-- ----------------------------------------------------------------------------
-- Routine Mutil_TexasPoker.sp_UpdateCornucopiaPerSeconds
-- ----------------------------------------------------------------------------
-- DELIMITER $$
-- 
-- DELIMITER $$
-- USE `Mutil_TexasPoker`$$
-- 
-- -- =============================================
-- -- Author:		peng cheng long
-- -- Create date: 2012-12-10
-- -- Description:	定时器更新积宝,传入需要更改的偏移量
-- -- =============================================
-- CREATE PROCEDURE [dbo].[sp_UpdateCornucopiaPerSeconds] 
-- 	@TotalOffsetCornucopia float=0
-- AS
-- BEGIN
-- 	SET NOCOUNT ON;
--     ---如果偏移量大于中心服需要偏移的，更新两个全局数据
--     IF EXISTS(SELECT * FROM t_Config WHERE CKey='OffSetCornucopia' AND FValue>=@TotalOffsetCornucopia)
--       BEGIN
--          UPDATE t_Config SET FValue=FValue-@TotalOffsetCornucopia WHERE  CKey='OffSetCornucopia'
--          UPDATE t_Config SET FValue=FValue+@TotalOffsetCornucopia WHERE  CKey='Cornucopia'
--          SELECT FValue AS FROMCornucopia,@TotalOffsetCornucopia AS OffsetCornucopia FROM t_Config WHERE CKey='Cornucopia'
--       END
--     ELSE
--       BEGIN
--       ---如果偏移量小于中心服需要偏移的，不改数据
--          SELECT FValue AS FROMCornucopia,0 AS OffsetCornucopia FROM t_Config WHERE CKey='Cornucopia'
--       END
-- END
-- 
-- $$
-- 
-- DELIMITER ;
-- 
-- ----------------------------------------------------------------------------
-- Routine Mutil_TexasPoker.sp_SynCornucopiaToDb
-- ----------------------------------------------------------------------------
-- DELIMITER $$
-- 
-- DELIMITER $$
-- USE `Mutil_TexasPoker`$$
-- 
-- -- =============================================
-- -- Author:		long
-- -- Create date: 2012-12-10
-- -- Description:	中心服务器定时更新内存的积宝数据
-- -- =============================================
-- CREATE PROCEDURE [dbo].[sp_SynCornucopiaToDb]
-- 	@Cornucopia float, 
-- 	@OffSetCornucopia float,
-- 	@SystemTotalWin float
-- AS
-- BEGIN
-- 	SET NOCOUNT ON;
-- 	BEGIN TRANSACTION
--     UPDATE t_Config set FValue=@OffSetCornucopia  WHERE CKey='OffSetCornucopia';
--     	IF @@ERROR <> 0
-- 			BEGIN
-- 			 ROLLBACK TRANSACTION
-- 			 RETURN 1
-- 			END
--     UPDATE t_Config set FValue=@Cornucopia WHERE CKey='Cornucopia';
--   	IF @@ERROR <> 0
-- 			BEGIN
-- 			 ROLLBACK TRANSACTION
-- 			 RETURN 1
-- 			END
--  UPDATE t_Config set FValue=@SystemTotalWin WHERE CKey='SystemTotalWin';
--   	IF @@ERROR <> 0
-- 			BEGIN
-- 			 ROLLBACK TRANSACTION
-- 			 RETURN 1
-- 			END
--     COMMIT TRANSACTION
--  RETURN 0
-- END
-- $$
-- 
-- DELIMITER ;
-- 
-- ----------------------------------------------------------------------------
-- Routine Mutil_TexasPoker.sp_AddGameLog
-- ----------------------------------------------------------------------------
-- DELIMITER $$
-- 
-- DELIMITER $$
-- USE `Mutil_TexasPoker`$$
-- 
-- -- =============================================
-- -- Author:		<Author,,Name>
-- -- Create date: <Create Date,,>
-- -- Description:	<Description,,>
-- -- =============================================
-- CREATE PROCEDURE [dbo].[sp_AddGameLog] 
-- @GameId int,
-- @ServerId int,
-- @Step int,
-- @UserId int,
-- @idx int,
-- @SeatId int,
-- @RoundNum int,
-- @ActionType tinyint,
-- @LeftTime int,
-- @GiveChip float,
-- @SiteChip float,
-- @Stake float,
-- @TotalChip float,
-- @CurrentState tinyint,
-- @Memo varchar(50)	
-- AS
-- BEGIN
--  SET NOCOUNT OFF;
--  INSERT INTO [Mutil_TexasPoker].[dbo].[Game_StepLog](GameId,ServerId,Step,UserId,idx,SeatId,RoundNum,ActionType,LeftTime,GiveChip,SiteChip,Stake,TotalChip,CurrentState,CreateTime,Memo)VALUES(@GameId,@ServerId,@Step,@UserId,@idx,@SeatId,@RoundNum,@ActionType,@LeftTime,@GiveChip,@SiteChip,@Stake,@TotalChip,@CurrentState,GETDATE(),@Memo) 
-- END
-- 
-- $$
-- 
-- DELIMITER ;
-- 
-- ----------------------------------------------------------------------------
-- Routine Mutil_TexasPoker.sp_AddCornucopiasRecord
-- ----------------------------------------------------------------------------
-- DELIMITER $$
-- 
-- DELIMITER $$
-- USE `Mutil_TexasPoker`$$
-- 
-- 
-- -- =============================================
-- -- Author:		peng cheng long
-- -- Create date: 2012-125
-- -- Description:	中心服定时批量增加积宝记录
-- -- =============================================
-- CREATE PROCEDURE [dbo].[sp_AddCornucopiasRecord]
-- 	@CornucopiaCallBack varchar(20),
-- 	@CornucopiaType tinyint,
-- 	@IsAllow bit=0,
-- 	@IsUsing bit=0,
-- 	@IsSend bit=0,
-- 	@ServerId int,
--     @RoomId int,
--     @GameId int,
--     @SeatId int,
--     @UserId int,
--     @idx int,
--     @NickName varchar(20),
--     @WinMoney int,
--     @CardType int,
--     @MaxCards varchar(20)
-- AS
-- BEGIN
-- 	SET NOCOUNT OFF;
--     INSERT INTO Bonus_CenterServerLog(CornucopiaCallBack,CornucopiaType,IsAllow,IsSend,IsUsing,ServerId,RoomId,GameId,SeatId,UserId,idx,NickName,WinMoney,CardType,MaxCards,WinTime) VALUES(@CornucopiaCallBack,@CornucopiaType,@IsAllow,@IsUsing,@IsSend,@ServerId,@RoomId,@GameId,@SeatId,@UserId,@idx,@NickName,@WinMoney,@CardType,@MaxCards,getdate())
-- END
-- 
-- $$
-- 
-- DELIMITER ;
-- 
-- ----------------------------------------------------------------------------
-- Routine Mutil_TexasPoker.sp_AddTableLog
-- ----------------------------------------------------------------------------
-- DELIMITER $$
-- 
-- DELIMITER $$
-- USE `Mutil_TexasPoker`$$
-- 
-- 
-- 
-- 
-- -- =============================================
-- -- Author:		long
-- -- Create date: 2013-1-21
-- -- Description:	add table log
-- -- =============================================
-- CREATE PROCEDURE [dbo].[sp_AddTableLog] 
-- @ServerId  int ,
-- @RoomdId int ,
-- @SeatId  int ,
-- @GameId  int ,
-- @UserId int ,
-- @idx int ,
-- @Money  float ,
-- @Stake float ,
-- @LeftMoney float ,
-- @Win float ,
-- @Memo varchar(50)	
-- AS
-- BEGIN
--  SET NOCOUNT OFF;
--  INSERT INTO Game_TableLog (ServerId ,RoomdId,SeatId ,GameId ,UserId,idx,[Money] ,Stake,LeftMoney,Win,CreateTime,Memo)VALUES(@ServerId ,@RoomdId,@SeatId ,@GameId ,@UserId,@idx,@Money ,@Stake,@LeftMoney,@Win,GETDATE(),@Memo) 
-- END
-- 
-- 
-- 
-- 
-- $$
-- 
-- DELIMITER ;
-- 
-- ----------------------------------------------------------------------------
-- Routine Mutil_TexasPoker.sp_UpdatePlayer
-- ----------------------------------------------------------------------------
-- DELIMITER $$
-- 
-- DELIMITER $$
-- USE `Mutil_TexasPoker`$$
-- 
-- 
-- 
-- -- =============================================
-- -- Author:		long
-- -- Create date: 2013-1-21
-- -- Description:	add table log
-- -- =============================================
-- CREATE PROCEDURE [dbo].[sp_UpdatePlayer] 
-- @UserId int ,
-- @Money  float ,
-- @Stake float ,
-- @GameBet float 
-- AS
-- BEGIN
--  SET NOCOUNT OFF;
--  UPDATE  PlayerInfo SET MONEY=@Money,STAKE=@Stake,GameBet=@GameBet WHERE userid=@UserId
-- END
-- 
-- 
-- $$
-- 
-- DELIMITER ;
-- 
-- ----------------------------------------------------------------------------
-- Routine Mutil_TexasPoker.sp_AddBonus_CenterServerLog
-- ----------------------------------------------------------------------------
-- DELIMITER $$
-- 
-- DELIMITER $$
-- USE `Mutil_TexasPoker`$$
-- 
-- 
-- 
-- -- =============================================
-- -- Author:		peng cheng long
-- -- Create date: 2013-1-22
-- -- Description:	中心服积宝记录
-- -- =============================================
-- CREATE PROCEDURE [dbo].[sp_AddBonus_CenterServerLog]
-- 	@CornucopiaCallBack varchar(20),
-- 	@CornucopiaType tinyint,
-- 	@IsAllow bit=0,
-- 	@IsUsing bit=0,
-- 	@IsSend bit=0,
-- 	@ServerId int,
--     @RoomId int,
--     @GameId int,
--     @SeatId int,
--     @UserId int,
--     @idx int,
--     @NickName varchar(20),
--     @WinMoney int,
--     @CardType int,
--     @MaxCards varchar(20)
-- AS
-- BEGIN
-- 	SET NOCOUNT OFF;
--     INSERT INTO Bonus_CenterServerLog(CornucopiaCallBack,CornucopiaType,IsAllow,IsSend,IsUsing,ServerId,RoomId,GameId,SeatId,UserId,idx,NickName,WinMoney,CardType,MaxCards,WinTime) VALUES(@CornucopiaCallBack,@CornucopiaType,@IsAllow,@IsUsing,@IsSend,@ServerId,@RoomId,@GameId,@SeatId,@UserId,@idx,@NickName,@WinMoney,@CardType,@MaxCards,getdate())
-- END
-- 
-- 
-- $$
-- 
-- DELIMITER ;
-- 
-- ----------------------------------------------------------------------------
-- Routine Mutil_TexasPoker.sp_AddBonus_GameServerLog
-- ----------------------------------------------------------------------------
-- DELIMITER $$
-- 
-- DELIMITER $$
-- USE `Mutil_TexasPoker`$$
-- 
-- 
-- 
-- -- =============================================
-- -- Author:		peng cheng long
-- -- Create date: 2013-1-22
-- -- Description:	中心服积宝记录
-- -- =============================================
-- CREATE PROCEDURE [dbo].[sp_AddBonus_GameServerLog]
-- 	@CornucopiaCallBack varchar(20),
-- 	@CornucopiaType tinyint,
-- 	@IsUsing bit=0,
-- 	@IsSend bit=0,
-- 	@ServerId int,
--     @RoomId int,
--     @GameId int,
--     @SeatId int,
--     @UserId int,
--     @idx int,
--     @NickName varchar(20),
--     @WinMoney int,
--     @CardType int,
--     @MaxCards varchar(20),
--     @Memo varchar(50)
-- AS
-- BEGIN
-- 	SET NOCOUNT OFF;
--     INSERT INTO Bonus_GameServerLog(CornucopiaCallBack,CornucopiaType,IsUsing,IsSend,ServerId,RoomId,GameId,SeatId,UserId,idx,NickName,WinMoney,CardType,MaxCards,WinTime,Memo) VALUES(@CornucopiaCallBack,@CornucopiaType,@IsUsing,@IsSend,@ServerId,@RoomId,@GameId,@SeatId,@UserId,@idx,@NickName,@WinMoney,@CardType,@MaxCards,getdate(),@Memo)
-- END
-- 
-- 
-- $$
-- 
-- DELIMITER ;
-- 
-- ----------------------------------------------------------------------------
-- Routine Mutil_TexasPoker.sp_GetUserInfo
-- ----------------------------------------------------------------------------
-- DELIMITER $$
-- 
-- DELIMITER $$
-- USE `Mutil_TexasPoker`$$
-- 
-- 
-- -- =============================================
-- -- Author:		peng cheng long
-- -- Create date: 2013-1-23
-- -- Description:	玩家首次登陆，获得此人详细信息
-- -- =============================================
-- CREATE PROCEDURE [dbo].[sp_GetUserInfo]
--     @UserName varchar(50),
--     @ServerId int
-- AS
-- BEGIN
-- 	SET NOCOUNT ON;	
--     SELECT UserId,GameBet,Stake,NickName,HeadImage,Sex,RealName,Icon,RankMoney,PlayCount,WinCount,MaxMoney,MaxHandCard,MaxWin,CurrentState FROM PlayerInfo WHERE  UserName=@UserName and ServerId=@ServerId	
-- END
-- 
-- $$
-- 
-- DELIMITER ;
-- 
-- ----------------------------------------------------------------------------
-- Routine Mutil_TexasPoker.sp_ServerLogoff
-- ----------------------------------------------------------------------------
-- DELIMITER $$
-- 
-- DELIMITER $$
-- USE `Mutil_TexasPoker`$$
-- 
--  
-- 
-- -- =============================================
-- -- Author:		peng cheng long
-- -- Create date: 2013-1-24
-- -- Description:	服务器注销
-- -- =============================================
-- CREATE PROCEDURE [dbo].[sp_ServerLogoff]
--     @ServerId int
-- AS
-- BEGIN
-- 	SET NOCOUNT ON;	
--     UPDATE dbo.t_ServerList SET State=0,LastLogOutTime=GETDATE() WHERE ServerId=@ServerId
--     RETURN @@ROWCOUNT    
-- END
-- 
-- 
-- $$
-- 
-- DELIMITER ;
-- 
-- ----------------------------------------------------------------------------
-- Routine Mutil_TexasPoker.sp_ServerLogin
-- ----------------------------------------------------------------------------
-- DELIMITER $$
-- 
-- DELIMITER $$
-- USE `Mutil_TexasPoker`$$
-- 
-- 
-- 
--  
-- 
-- -- =============================================
-- -- Author:		peng cheng long
-- -- Create date: 2013-1-23
-- -- Description:	服务器登录
-- -- =============================================
-- CREATE PROCEDURE [dbo].[sp_ServerLogin]
--     @ServerId int,
--     @ServerIp varchar(50)
-- AS
-- BEGIN
-- 	SET NOCOUNT ON;	
--     UPDATE dbo.t_ServerList SET State=1,LastLoginTime=GETDATE() WHERE ServerId=@ServerId AND ServerIp=@ServerIp AND State !=1
--     RETURN @@ROWCOUNT    
-- END
-- 
-- 
-- 
-- 
-- $$
-- 
-- DELIMITER ;
-- 
-- ----------------------------------------------------------------------------
-- Routine Mutil_TexasPoker.sp_ClearServerLogin
-- ----------------------------------------------------------------------------
-- DELIMITER $$
-- 
-- DELIMITER $$
-- USE `Mutil_TexasPoker`$$
-- 
-- 
-- 
--  
-- 
-- -- =============================================
-- -- Author:		peng cheng long
-- -- Create date: 2013-1-24
-- -- Description:	清除所有服务器登录
-- -- =============================================
-- CREATE PROCEDURE [dbo].[sp_ClearServerLogin]
-- AS
-- BEGIN
-- 	SET NOCOUNT ON;	
--     UPDATE dbo.t_ServerList SET State=0
--     IF @@ROWCOUNT<>0
--        BEGIN    
--         RETURN 1
--        END
--     RETURN 0
-- END
-- 
-- 
-- $$
-- 
-- DELIMITER ;
-- 
-- ----------------------------------------------------------------------------
-- Routine Mutil_TexasPoker.sp_AddPlayMoneyLog
-- ----------------------------------------------------------------------------
-- DELIMITER $$
-- 
-- DELIMITER $$
-- USE `Mutil_TexasPoker`$$
-- 
-- 
-- 
-- 
-- 
-- -- =============================================
-- -- Author:		peng cheng long
-- -- Create date: 2012-12-12
-- -- Description:	增加一条游戏下注了钱,游戏结束赢输钱
-- -- =============================================
-- CREATE PROCEDURE [dbo].[sp_AddPlayMoneyLog]
--     @UserId int,
--     @idx int,
-- 	@Bet float,
--     @Win float,
--     @stake float
-- AS
-- BEGIN
-- 	SET NOCOUNT OFF;
--     INSERT INTO AccountMoneyLog(UserId,idx,Bet,Win,CreateTime) VALUES(@UserId,@idx,@Bet,@Win,getdate())
--     --SAVE TEMP BET ,WHEN GAME OVER,CLEAR
--     IF  @Bet>0
--      BEGIN
--       UPDATE dbo.PlayerInfo SET GameBet=GameBet+@Bet,Stake=@stake  WHERE UserId=@UserId
--      END  
-- END
-- 
-- 
-- 
-- 
-- $$
-- 
-- DELIMITER ;
-- 
-- ----------------------------------------------------------------------------
-- Routine Mutil_TexasPoker.sp_SaveGameWinner
-- ----------------------------------------------------------------------------
-- DELIMITER $$
-- 
-- DELIMITER $$
-- USE `Mutil_TexasPoker`$$
-- 
-- 
-- 
-- 
-- 
-- -- =============================================
-- -- Author:		long
-- -- Create date: 2013-1-28
-- -- Description:	保存游戏结束时候玩家的输赢情况，同时更新账号筹码下注
-- -- =============================================
-- CREATE PROCEDURE [dbo].[sp_SaveGameWinner] 
-- @ServerId  int ,
-- @RoomdId int ,
-- @SeatId  int ,
-- @GameId  int ,
-- @UserId int ,
-- @idx int ,
-- @Money  float ,
-- @Stake float ,
-- @LeftMoney float ,
-- @Win float ,
-- @Memo varchar(50)	
-- AS
-- BEGIN
--  SET NOCOUNT OFF;
--  INSERT INTO Game_TableLog (ServerId ,RoomdId,SeatId ,GameId ,UserId,idx,[Money] ,Stake,LeftMoney,Win,CreateTime,Memo)VALUES(@ServerId ,@RoomdId,@SeatId ,@GameId ,@UserId,@idx,@Money ,@Stake,@LeftMoney,@Win,GETDATE(),@Memo) 
--   IF @@ROWCOUNT<>1
--      BEGIN
--       RETURN 0
--      END
--   UPDATE  PlayerInfo SET MONEY=@Money,STAKE=@Stake,GameBet=0 WHERE userid=@UserId
--   RETURN @@ROWCOUNT
-- END
-- 
-- 
-- 
-- 
-- 
-- $$
-- 
-- DELIMITER ;
-- 
-- ----------------------------------------------------------------------------
-- Routine Mutil_TexasPoker.sp_UpdateUserHeadImage
-- ----------------------------------------------------------------------------
-- DELIMITER $$
-- 
-- DELIMITER $$
-- USE `Mutil_TexasPoker`$$
-- 
-- 
-- -- =============================================
-- -- Author:		peng cheng long
-- -- Create date: 2012-12-18
-- -- Description:	更新玩家头像
-- -- =============================================
-- CREATE PROCEDURE [dbo].[sp_UpdateUserHeadImage]
--     @UserId int,
-- 	@HeadImage image
-- AS
-- BEGIN
-- 	SET NOCOUNT OFF;
--     UPDATE  dbo.PlayerInfo SET HeadImage=@HeadImage WHERE USERID=@UserId
-- END
-- 
-- $$
-- 
-- DELIMITER ;
-- 
-- ----------------------------------------------------------------------------
-- Routine Mutil_TexasPoker.sp_AddEndGameLog
-- ----------------------------------------------------------------------------
-- DELIMITER $$
-- 
-- DELIMITER $$
-- USE `Mutil_TexasPoker`$$
-- 
-- 
-- 
-- 
-- -- =============================================
-- -- Author:		long
-- -- Create date: 2012-12-20
-- -- Description:	游戏结束，分配边池的钱，系统抽成
-- -- =============================================
-- CREATE PROCEDURE [dbo].[sp_AddEndGameLog]
-- 	@GameId int, 
--     @BonusPools varchar(50),
--     @SystemWinPools varchar(50),
--     @SystemWin float,
--     --转换多少积宝由中心服控制@ToCornucopia int,
--     @Winners varchar(50),
--     @idx_win varchar(200),
--     @WinMoneys varchar(50),
--     @MaxHands varchar(100)
-- AS
-- BEGIN
-- 	SET NOCOUNT OFF
-- 		INSERT INTO Game_EndLog 
--            ([GameId],[BonusPools]
--            ,[SystemWinPools]
--            ,[SystemWin]        
--            ,[Winners]
--            ,[idx_win]
--            ,[WinMoneys]
--            ,[MaxHands]
--            ,[EndTime])
--         VALUES(@GameId,@BonusPools,@SystemWinPools,@SystemWin,@Winners,@idx_win,@WinMoneys,@MaxHands,getdate());
-- END
-- 
-- 
-- 
-- $$
-- 
-- DELIMITER ;
-- 
-- ----------------------------------------------------------------------------
-- Routine Mutil_TexasPoker.sp_AddBeginGameLog
-- ----------------------------------------------------------------------------
-- DELIMITER $$
-- 
-- DELIMITER $$
-- USE `Mutil_TexasPoker`$$
-- 
-- 
-- 
-- 
-- 
-- 
-- -- =============================================
-- -- Author:		peng cheng long
-- -- Create date: 2012-12-12
-- -- Description:	增加一条游戏开始的记录
-- -- =============================================
-- CREATE PROCEDURE [dbo].[sp_AddBeginGameLog]
--     @ServerId int,
-- 	@RoomId int,
-- 	@RoomCode int,
--     @RoomName varchar(50),
--     @PlayerNum int,
--     @SeatCount int,
--     @prevId int,
--     @PublicCard varchar(50),
--     @SeatUserIds varchar(100),
--     @SeatIdx varchar(200),
--     @DealerId int,
--     @MinBindUserId int,
--     @MinBind int,
--     @MaxBindUserId int,
--     @MaxBind int,
--     @DlayTime int,
--     @MinStake int,
--     @MaxStake int,
--     @NewChip int,
--     @NewUserIds varchar(50),
--     @WatchUserIds varchar(50),
--     @StartChips varchar(50),
--     @SeatUserId1 int,
--     @SeatUserId2 int,
--     @SeatUserId3 int,
--     @SeatUserId4 int,
--     @SeatUserId5 int,
--     @SeatUserId6 int,
--     @SeatUserId7 int,
--     @SeatUserId8 int,
--     @SeatUserId9 int,
-- @HandCard1 varchar(50),
-- @HandCard2 varchar(50),
-- @HandCard3 varchar(50),
-- @HandCard4 varchar(50),
-- @HandCard5 varchar(50),
-- @HandCard6 varchar(50),
-- @HandCard7 varchar(50),
-- @HandCard8 varchar(50),
-- @HandCard9 varchar(50),
-- @PokerIndexs varchar(200)
-- AS
-- BEGIN
-- 	SET NOCOUNT ON;
--     INSERT INTO dbo.Game_BeginLog(ServerId,RoomId,RoomCode,RoomName,PlayerNum,SeatCount,prevId,PublicCard,SeatUserIds,SeatIdx,DealerId,MinBindUserId,MinBind,MaxBindUserId,MaxBind,DlayTime,MinStake,MaxStake,NewChip,NewUserIds,WatchUserIds,StartChips,SeatUserId1,SeatUserId2,SeatUserId3,SeatUserId4,SeatUserId5,SeatUserId6,SeatUserId7,SeatUserId8,SeatUserId9,HandCard1,HandCard2,HandCard3,HandCard4,HandCard5,HandCard6,HandCard7,HandCard8,HandCard9,PokerIndexs,StartTime)  VALUES(@ServerId,@RoomId,@RoomCode,@RoomName,@PlayerNum,@SeatCount,@prevId,@PublicCard,@SeatUserIds,@SeatIdx,@DealerId,@MinBindUserId,@MinBind,@MaxBindUserId,@MaxBind,@DlayTime,@MinStake,@MaxStake,@NewChip,@NewUserIds,@WatchUserIds,@StartChips,@SeatUserId1,@SeatUserId2,@SeatUserId3,@SeatUserId4,@SeatUserId5,@SeatUserId6,@SeatUserId7,@SeatUserId8,@SeatUserId9,@HandCard1,@HandCard2,@HandCard3,@HandCard4,@HandCard5,@HandCard6,@HandCard7,@HandCard8,@HandCard9,@PokerIndexs,getdate())
--     ; select SCOPE_IDENTITY()
-- END
-- 
-- 
-- 
-- 
-- 
-- $$
-- 
-- DELIMITER ;
-- 
-- ----------------------------------------------------------------------------
-- Routine Mutil_TexasPoker.sp_AddSynMoneyLog
-- ----------------------------------------------------------------------------
-- DELIMITER $$
-- 
-- DELIMITER $$
-- USE `Mutil_TexasPoker`$$
-- 
-- -- =============================================
-- -- Author:		long
-- -- Create date: 2012-12-11
-- -- Description:	中心服务器定时更新内存的积宝数据,同时保存同步记录
-- -- =============================================
-- CREATE PROCEDURE [dbo].[sp_AddSynMoneyLog]
-- 	@IsSynSuc bit=0, 
-- 	@SynCornucopia float, 
-- 	@SynOffSetCornucopia float,
-- 	@SynSystemTotalWin float
-- AS
-- BEGIN
-- 	SET NOCOUNT ON;
-- 	BEGIN TRANSACTION
--     INSERT INTO [Db_Wandian_Log].[dbo].[t_SynMoneyLog]([isSynSuc] ,[SynCornucopia] ,[SynOffSetCornucopia]  ,[SynSystemTotalWin],[SynTime])
--          VALUES
--            (@IsSynSuc
--            ,@SynCornucopia
--            ,@SynOffSetCornucopia
--            ,@SynSystemTotalWin
--            ,getdate())
--     	IF @@ERROR <> 0
-- 			BEGIN
-- 			 ROLLBACK TRANSACTION
-- 			 RETURN 1
-- 			END
--     COMMIT TRANSACTION
--  RETURN 0
-- END
-- $$
-- 
-- DELIMITER ;
-- 
-- ----------------------------------------------------------------------------
-- Routine Mutil_TexasPoker.sp_AddUserInfo
-- ----------------------------------------------------------------------------
-- DELIMITER $$
-- 
-- DELIMITER $$
-- USE `Mutil_TexasPoker`$$
-- 
-- 
-- 
-- 
-- 
-- -- =============================================
-- -- Author:		peng cheng long
-- -- Create date: 2012-12-27
-- -- Description:	user login texas poker first time ,import info from accounttable,initailize base info
-- -- =============================================
-- CREATE PROCEDURE [dbo].[sp_AddUserInfo]
-- 	@idx int,
--     @ServerId int,
--     @UserName varchar(50),
--     @NickName varchar(50),
--     @Sex bit,
--     @Icon varchar(50)
-- AS
-- BEGIN
-- 	SET NOCOUNT ON
--     INSERT INTO PlayerInfo(idx,ServerId,UserName,NickName,Sex,Icon,CreateDate)VALUES(@idx,@ServerId,@UserName,@NickName,@Sex,@Icon,GETDATE())
--     ; select SCOPE_IDENTITY()
-- END
-- 
-- 
-- 
-- 
-- $$
-- 
-- DELIMITER ;
-- 
-- ----------------------------------------------------------------------------
-- Routine Mutil_TexasPoker.sp_GetFriendList
-- ----------------------------------------------------------------------------
-- DELIMITER $$
-- 
-- DELIMITER $$
-- USE `Mutil_TexasPoker`$$
-- 
-- 
-- -- =============================================
-- -- Author:		<long>
-- -- Create date: <2012-10-25>
-- -- Description:	<根据用户id查找好友列表>
-- -- =============================================
-- CREATE PROCEDURE [dbo].[sp_GetFriendList]
-- 	@UserId int
-- AS
-- BEGIN
-- 	SET NOCOUNT ON;
--   Select UserId,NickName,HeadImage,Sex,IsPlaying,CurrentRoomId,Money,Icon From  PlayerInfo where UserId in (
-- Select UserId From t_Friends where friendid=@UserId and state=1
-- union
-- Select friendid From t_Friends where UserId=@UserId and state=1
-- )
-- END
-- 
-- $$
-- 
-- DELIMITER ;
-- 
-- ----------------------------------------------------------------------------
-- Routine Mutil_TexasPoker.Public_InsertAccountMoney
-- ----------------------------------------------------------------------------
-- DELIMITER $$
-- 
-- DELIMITER $$
-- USE `Mutil_TexasPoker`$$
-- 
--  	
-- -- =============================================
-- -- 记录玩家下注记录
-- -- =============================================
-- CREATE PROCEDURE [dbo].[Public_InsertAccountMoney] 
-- (
-- @idx int,			-- 玩家账户ID
-- @bet float,			-- 玩家下注额
-- @win float			-- 玩家赢额
-- )
-- AS
-- SET NOCOUNT ON;
-- 	insert into Public_AccountMoneyLog(idx,bet,win) values (@idx,@bet,@win)
-- 
-- --对他上级代理做账目更新
-- 	declare 
-- 			@acctype	smallint,		--1，11 纯外网玩家账号 2 ，21店内玩家账号
-- 			@Account	varchar(17),
-- 			@Manger		varchar(17)  
-- 	select 	@acctype= [TYPE],@Account=Account,@Manger=Agent from LinkDB_Account.AccountDB.dbo.AccountTable where idx = @idx
-- 	if @@ROWCOUNT=0
-- 		begin
-- 			return 0
-- 		end
-- 	
-- 	declare 
-- 			@TempAcc	varchar(17),
-- 			@nowtime	datetime = getdate(),
-- 			@nowDay		int,
-- 			@nowMonth	int,
-- 			@nowYear	int
-- 	set @TempAcc	= @Account
-- 	set @nowDay		= DATEPART(day, @nowtime)
-- 	set @nowMonth	= DATEPART(month,@nowtime)
-- 	set @nowYear	= DATEPART(year,@nowtime)
-- 	
-- 	declare 
-- 		@lastDay	int,
-- 		@lastMonth	int,
-- 		@lastYear	int,
-- 		@no_index	int = 0
-- 		
-- 	if(@acctype <> 2 and @acctype <> 21)----  纯外网玩家账号
-- 	begin
-- 		select @Manger=Agent from LinkDB_Account.AccountDB.dbo.AccountTable where Account = @TempAcc
-- 		while  @@ROWCOUNT <>0 
-- 			begin
-- 				if (@Manger <> 'admin')
-- 				begin
-- 					set @nowtime = '1999-1-1'
-- 					select @nowtime=CreateTime ,@no_index = [index_no]  from Public_AgentMoneyLog where [index_no] =
-- 					(
-- 						select max([index_no])   from Public_AgentMoneyLog where Account = @Manger 
-- 					)
-- 					set @lastDay	=  DATEPART(day, @nowtime)
-- 					set @lastMonth	=  DATEPART(month, @nowtime)
-- 					set @lastYear	=  DATEPART(year,@nowtime)
-- 					if (@nowDay =  @lastDay and @nowMonth = @lastMonth and @nowYear=@lastYear) 
-- 						begin  
-- 							update Public_AgentMoneyLog set bet=bet+@bet,Win = Win+@Win where Account = @Manger and [index_no] = [index_no]
-- 						end
-- 					else 
-- 						begin 
-- 							insert Public_AgentMoneyLog(Account,bet,win) values ( @Manger,@bet,@Win)
-- 						end
-- 					set @TempAcc = @Manger
-- 					select @Manger=Agent from LinkDB_Account.AccountDB.dbo.AccountTable where Account = @TempAcc
-- 				end
-- 				else	
-- 					break;
-- 			end	
-- 	end
-- 	else--店内账号
-- 		begin		    
-- 				if (@Manger <> 'admin')-- 先更新店的账目
-- 					begin
-- 							set @nowtime = '1999-1-1'
-- 							select @nowtime=CreateTime ,@no_index = [index_no]  from Public_AgentMoneyLog where [index_no] =
-- 							(
-- 								select max([index_no])   from Public_AgentMoneyLog where Account = @Manger 
-- 							)
-- 							set @lastDay	=  DATEPART(day, @nowtime)
-- 							set @lastMonth	=  DATEPART(month, @nowtime)
-- 							set @lastYear	=  DATEPART(year,@nowtime)
-- 							if (@nowDay =  @lastDay and @nowMonth = @lastMonth and @nowYear=@lastYear) 
-- 								begin  
-- 									update Public_AgentMoneyLog set bet=bet+@bet,Win = Win+@Win where Account = @Manger and [index_no] = [index_no]
-- 								end
-- 		   					else 
-- 								begin 
-- 									insert Public_AgentMoneyLog(Account,bet,win) values ( @Manger,@bet,@Win)
-- 								end
-- 					end
-- 				else
-- 					return 1
-- 				set @TempAcc = @Manger--在从server_list里面找店的上级代理 
-- 				select @Manger= UserManager from LinkDB_casino.casino_central.dbo.Server_List  where Account = @TempAcc
-- 				while  @@ROWCOUNT <>0 
-- 					begin
-- 						if (@Manger <> 'admin')
-- 							begin
-- 								set @nowtime = '1999-1-1'
-- 								select @nowtime=CreateTime ,@no_index = [index_no]  from Public_AgentMoneyLog where [index_no] =
-- 								(
-- 									select max([index_no])   from Public_AgentMoneyLog where Account = @Manger 
-- 								)
-- 								set @lastDay	=  DATEPART(day, @nowtime)
-- 								set @lastMonth	=  DATEPART(month, @nowtime)
-- 								set @lastYear	=  DATEPART(year,@nowtime)
-- 								if (@nowDay =  @lastDay and @nowMonth = @lastMonth and @nowYear=@lastYear) 
-- 									begin  
-- 										update Public_AgentMoneyLog set bet=bet+@bet,Win = Win+@Win where Account = @Manger and [index_no] = [index_no]
-- 									end
-- 		   						else 
-- 									begin 
-- 										insert Public_AgentMoneyLog(Account,bet,win) values ( @Manger,@bet,@Win)
-- 									end
-- 								set @TempAcc = @Manger
-- 								select @Manger= UserManager from LinkDB_casino.casino_central.dbo.Server_List  where Account = @TempAcc
-- 							end
-- 						else	
-- 							 break;
-- 					end
-- 		end
-- 
-- return 1
-- 	SET NOCOUNT OFF;
-- $$
-- 
-- DELIMITER ;
-- SET FOREIGN_KEY_CHECKS = 1;;
